Alignment — data must start at addresses divisible by alignment.
1struct Bad {2 char a; // 1 byte3 int b; // 4 bytes (might need padding)4}; // sizeof might be 8, not 556struct Good {7 int b; // 4 bytes8 char a; // 1 byte + 3 padding9}; // sizeof is 8 (better cache usage)
alignof and alignas:
1std::cout << alignof(int); // 42std::cout << alignof(double); // 834alignas(64) char cache_line[64]; // aligned to 64 bytes
Why it matters: