about pack and align for C/C++
http://msdn.microsoft.com/en-us/library/2e70t5y1(VS.80).aspx
#pragma
pack( n )
n : Valid values are 1, 2, 4, 8, and 16.the
alignment of a member will be on a boundary that is either a multiple of
n
or
a multiple of the size of the member
,
whichever is smaller.
The
default value for n
is 8
³ÉÔ±±äÁ¿¶ÔÆ룺ѡn
ºÍ¸Ã³ÉÔ±³¤¶È
µÄ
×îСֵ(µÄ±¶Êý)
½á¹¹ABCDÖÐdµÄ¶ÔÆ뷽ʽ£¬Ñ¡nºÍsizeof(d)µÄ×îСֵ8£¬È»ºó°´8×Ö½Ú¶ÔÆ룡£¡£¡
sizeof´óС£ºÑ¡n
ºÍ×î´ó³É
Ô±³¤¶È
µÄ×îСֵ£¬¶ÔÆë
Àý×Ó£º
#pragma
pack(8)
struct ABCD
{
bool
b;
short s;
double d;
};
int
main()
{
cout << offsetof(ABCD,
b) << endl;
cout << offsetof(ABCD,
s) << endl;
cout << offsetof(ABCD,
d) << endl;
cout << sizeof(ABCD) << endl;
}
output
is:
0
2
8
16
http://msdn.microsoft.com/en-us/library/83ythb65(VS.71).aspx
__declspec( align( n ) )
__declspec( align() ) ºÍ #pragma pack
ÊÇÒ»¶ÔÐֵܣ¬Ç°Õ߹涨Á˶ÔÆëµÄ×îСֵ£¬ºóÕ߹涨Á˶ÔÆëµÄ×î´óÖµ£¬Á½Õßͬʱ³öÏÖʱ£¬Ç°ÕßÓµÓиü¸ßµÄÓÅÏȼ¶¡£
Àý×Ó£º
#define
CACHE_ALIGN 64
// Force each structure to be
in a different cache line.
struct
__declspec(align(CACHE_ALIGN)) CUSTINFOAA {
DWORD
dwCustomerID; // Mostly read-only
wchar_t
szName[100]; // Mostly read-only
// Force the following members to be in a different cache line.
__declspec(align(CACHE_ALIGN))
int
nBalanceDue; // Read-write
FILETIME
ftLastOrderDate; // Read-write
};
int
main()
{
cout <<
offsetof(CUSTINFOAA, dwCustomerID) << endl;
cout
<< offsetof(CUSTINFOAA, szName) << endl;
cout
<< offsetof(CUSTINFOAA, nBalanceDue) << endl;
cout << offsetof(CUSTINFOAA, ftLastOrderDate) <<
endl;
cout << sizeof(CUSTIN
Ïà¹ØÎĵµ£º
ÕâƪÈÕÖ¾»¹ÊÇÏÈ´ÓÒ»¸öÄܹ»ÔËÐÐÆðÀ´µÄÀý×Ó³ö·¢£¬Ò»µ©ÄÜ˳ÀûµÄ¿´µ½³ÌÐòµÄ³É¹¦ÔËÐУ¬ÄÇô½ÓÏÂÀ´µÄʼþÎÒÏëÓ¦¸ÃÊÇÎÊΪʲôÁË£¿ËƺõÕâÑù¸ü¼ÓÈÝÒ×Àí½âºÍÕÆÎÕ¡£
¶ÔÓÚsocket³ÌÐòµÄ¸ÅÄîÕâÀï¾Í²»¶àдÁË£¬µ«ÎÒÏàÐÅ£¬Èç¹ûÄÜ¿´ÍêÕâÕûƪÎÄÕ£¬ÎÒÏàÐŲ»»áÔÙÓÐÕâÑùµÄÒÉÎʵġ£
ÏÂÃ潫±àдһ¸öc/s½á¹¹µÄ³ÌÐò£¬Ö÷Òª¹¦ÄÜÊÇclient½«Ïòserver·¢Ë ......
http://www.mathworks.com/access/helpdesk/help/techdoc/apiref/mexfunction.html
mexFunction (C and Fortran) -
Entry point to C/C++ or Fortran MEX-file
C Syntax
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs,
const mxArray *prhs[]);
Fortran
Syntax
subrouti ......
1.´óβ(big_endian)Сβ(little_endian)µÄÎÊÌâ
»ùÓÚWebµÄ²âÊÔÈí¼þÊÇÓÉC++Êý¾Ý²É¼¯·þÎñÆ÷³ÌÐòºÍ¿Í»§¶ËJavaÏÔʾ³ÌÐòÁ½²¿·Ö¹¹³É£¬Ç°ÕßÓÃC++£¬ºóÕßJavaÓïÑÔ£¬´æÔÚÊý¾ÝÒÆÖ²ÎÊÌâ¡£ÒòΪ
ÔÚ¼ÆËã»úϵͳÖУ¬µ±°üº¬Êý×ֵĶþ½øÖÆÎļþ´ÓÒ»¸ö½á¹¹ÒƵ½ÁíÒ»½á¹¹Ê±£¬¾Í³öÏÖ´óβСβÎÊÌâ¡£²»Í¬CPUÔÚ¶à×Ö½ÚÊý£¨ÈçËÄ×Ö½Úint£©´æ´¢Ê±ÓÐÁ½ÖÖ·½·¨ ......
ÕÆÎÕÎı¾Îļþ¶ÁдµÄ·½·¨
Á˽â¶þ½øÖÆÎļþµÄ¶Áд·½·¨
C++ÎļþÁ÷£º
fstream¡¡¡¡// ÎļþÁ÷
ifstream¡¡ // ÊäÈëÎļþÁ÷
ofstream¡¡ // Êä³öÎļþÁ÷
//´´½¨Ò»¸öÎı¾Îļþ²¢Ð´ÈëÐÅÏ¢
//ͬÏòÆÁÄ»ÉÏÊä³öÐÅÏ¢Ò»Ñù½«ÐÅÏ¢Êä³öÖÁÎļþ
#include<iomanip.h>
#include<fstream.h>
void main()
{
¡¡¡¡ofstream f1("d:\\ ......