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
Ïà¹ØÎĵµ£º
http://www.trendcaller.com/2009/05/hadoop-should-target-cllvm-not-java.html
Sunday, May 10, 2009
Hadoop should target C++/LLVM, not Java (because of watts)
< type="text/javascript">
digg_url="http://www.trendcaller.com/2009/05/hadoop-should-target-cllvm-not-java.html";
Over the years, ......
ÕâÆªÈÕÖ¾»¹ÊÇÏÈ´ÓÒ»¸öÄܹ»ÔËÐÐÆðÀ´µÄÀý×Ó³ö·¢£¬Ò»µ©ÄÜ˳ÀûµÄ¿´µ½³ÌÐòµÄ³É¹¦ÔËÐУ¬ÄÇô½ÓÏÂÀ´µÄʼþÎÒÏëÓ¦¸ÃÊÇÎÊΪʲôÁË£¿ËƺõÕâÑù¸ü¼ÓÈÝÒ×Àí½âºÍÕÆÎÕ¡£
¶ÔÓÚ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 Ñ¡Ôñnew->project->win32 console project£»
ÔÚÕâÒ»²½µÄÑ¡¿òÉÏÓÐÒ»¸öÑ¡ÏîÊÇ create dictionary for solution, ÎÒ²»ÖªµÀÕâ¸ö¾ßÌåÊÇʲô×÷Óã¬Ñ¡ÁËÖ®ºó»áÏîÄ¿³öÏÖÁ½²ãÎļþ¼Ð£¬±ÈÈçÄã´´½¨Ò»¸öÃüÃûΪtestµÄÏîÄ¿£¬»áÉú³ÉtestÎļþ¼Ð£¬testÖаüº¬ÁíÒ»¸ötestÎļþ¼Ð£¬ÄãµÄÏîĿʵ¼ÊÉÏ·ÅÔÚÁËÄÚ²ãte ......
ÕÆÎÕÎı¾Îļþ¶ÁдµÄ·½·¨
Á˽â¶þ½øÖÆÎļþµÄ¶Áд·½·¨
C++ÎļþÁ÷£º
fstream¡¡¡¡// ÎļþÁ÷
ifstream¡¡ // ÊäÈëÎļþÁ÷
ofstream¡¡ // Êä³öÎļþÁ÷
//´´½¨Ò»¸öÎı¾Îļþ²¢Ð´ÈëÐÅÏ¢
//ͬÏòÆÁÄ»ÉÏÊä³öÐÅÏ¢Ò»Ñù½«ÐÅÏ¢Êä³öÖÁÎļþ
#include<iomanip.h>
#include<fstream.h>
void main()
{
¡¡¡¡ofstream f1("d:\\ ......