Reference url:http://blog.csdn.net/hairetz/article/details/4084088
0 byte justification As I understand it, it's easy for the CPU to take all the data at once and improve the execution of the code.
1-byte alignment rules
(1) The first member of the struct is offset as 0, and each subsequent member stores the starting position from which the member size (original type), or the member's Child member size (array), or the integer multiple address of the maximum child member size in the member is stored
(2) The total size of the struct, which is the result of sizeof, must be an integer multiple of its internal maximum member. Not enough to be done.
The following is the memory distribution in the Win7 x86_64 vs2015 x64 mode compilation mode
Variable b
Variable A
2 vs2015 such as compiler default is #pragma pack (8), so test our rules will be normal; GCC defaults to #pragma pack (4), and GCC only supports 1,2,4 alignment. The alignment value calculated in the above rule cannot be greater than the n value specified by the #pragma pack
C + + byte alignment