C++

C-CPP-Programming-in-case-of

Category & Tags: C, C++, CPP, Programming

Data Structure Alignment 数据结构对齐 # x86-64 architecture # Overall rule: any data structure/element should be accessed by CPU with minimum CPU cycles. A 32bit CPU can access 4Bytes in one cycle, while a 64bit one can access 8Bytes. When a memory access is not aligned, it is said to be misaligned (wiki). Thus, there are two practical rules for us to understand compiler’s padding: Rule 1: any basic data structure/element/variable should be aligned so that their beginning address is divisible (任何变量的开始地址都能被自己的大小整除,即:当被访问的数据长度为 n 字节时,数据地址为 n 字节对齐。). ...