Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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:

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


Ïà¹ØÎĵµ£º

C/C++±ê×¼¿âʹÓÃ

ÊÕ¼¯ÁË¿´Ò»ÏÂC/C++±ê×¼¿âʹÓõÄÏà¹ØÍøÕ¾£º
GNU¹ÙÍø£º
http://www.gnu.org/
¸ÃÍøÕ¾°üº¬C/C++±ê×¼¿âµÄʹÓ÷¶Àý£¬ÖµµÃ²Î¿¼£º
http://www.cplusplus.com/
ÔÚǶÈëʽµÚÈý·½Èí¼þÒÆÖ²Ê±£¬»áʹÓÃSTLÄ£°å¿â×÷ÏàÓ¦ÒÆÖ²£¬ÈçAndroidƽ̨JNI·â×°¼°ÒÆÖ²µÈ¡£
¸ÃÍøÕ¾½éÉÜstlportµÄʹÓã¬stlportÒѿɳɹ¦ÒÆÖ²ÖÁAndroidµÈǶÈëʽƽ̨£¬²¢Ç ......

entry point to c/c++ or Fortran MEX file

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 ......

JavaÓëCͨÐÅҪעÒâµÄ¼¸¸öÎÊÌâ

1.´óβ(big_endian)Сβ(little_endian)µÄÎÊÌâ
»ùÓÚWebµÄ²âÊÔÈí¼þÊÇÓÉC++Êý¾Ý²É¼¯·þÎñÆ÷³ÌÐòºÍ¿Í»§¶ËJavaÏÔʾ³ÌÐòÁ½²¿·Ö¹¹³É£¬Ç°ÕßÓÃC++£¬ºóÕßJavaÓïÑÔ£¬´æÔÚÊý¾ÝÒÆÖ²ÎÊÌâ¡£ÒòΪ
ÔÚ¼ÆËã»úϵͳÖУ¬µ±°üº¬Êý×ֵĶþ½øÖÆÎļþ´ÓÒ»¸ö½á¹¹ÒƵ½ÁíÒ»½á¹¹Ê±£¬¾Í³öÏÖ´óβСβÎÊÌâ¡£²»Í¬CPUÔÚ¶à×Ö½ÚÊý£¨ÈçËÄ×Ö½Úint£©´æ´¢Ê±ÓÐÁ½ÖÖ·½·¨ ......

C¿ª·¢ÖжѺÍÕ»µÄ²î±ð

1£¬Õ»Çø£¨stack£©—   ÓɱàÒëÆ÷×Ô¶¯·ÖÅäÊÍ·Å£¬´æ·Åº¯ÊýµÄ²ÎÊýÖµ£¬¾Ö²¿±äÁ¿µÄÖµµÈ¡£Æä²Ù×÷·½Ê½ÀàËÆÓÚÊý¾Ý½á¹¹ÖеÄÕ»¡£ ÀýÈ磬ÉùÃ÷ÔÚº¯ÊýÖеÄÒ»¸ö¾Ö²¿±äÁ¿int b£»ÏµÍ³×Ô¶¯ÔÚÕ»ÖÐΪb¿ª±Ù¿Õ¼ä¡£Ö»ÒªÕ»µÄÊ£Óà¿Õ¼ä´óÓÚËùÉêÇë¿Õ¼ä£¬ÏµÍ³½«Îª³ÌÐòÌṩÄڴ棬·ñÔò½«±¨Òì³£ÌáʾջÒç³ö¡£±ÈÈ磺
char* AllocStrfromStack ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ