Compile the CompilerProgramTime alignment.
32Bit C ++Use default 8To improve the running efficiency, the compiler tries its best to put the data in the field to improve the memory hit rate. That is, suppose there is an intType data, int4Bytes (if no bounds is specified, the default bounds 8 is used.). If the value is smaller than the default peer interface, the value is 4., The intType data should be stored in memory address 4To facilitate searching. In fact, the compiler will allocate a certain amount of space for the variables in the memory. Their placement is not compact and put together one by one, because this is not conducive to the compiler efficiency. The example of structured storage is as follows, in the memory, the storage of variables alignment with the largest number of bytes of the variables. Why is the maximum alignment required? A struct:
Type struct
{
Int A;
Char C;
Short S;
} Teststruct;
Imagine if S is usedThe two bytes of the variable are aligned, which causes intTypeIt cannot be stored in the byte group where the compiler accesses data at a time. It is forced to be allocated in different byte arrays.
during alignment, if the variable cannot be stored in a byte array, it is automatically stored in the next byte array. In fact, alignment is not our job, it is compiled, but if we can understand alignment well, the Program Code can be better optimized. The benefits are also described in the previous article . http://www.cnblogs.com/IamEasy_Man/archive/2009/12/13/1623187.html