~/talk

When the Structs Align ... and When They Don't

Talkat Core C++ 2025 · on Sunday, 2025-10-19· [c-and-cpp]
links:none on file
slides:none on file

Explains C++ alignment rules and tools like alignas and operator new(alignment), shows that misaligned placement new is undefined but x86 usually works while many embedded CPUs fault, and that UBSanitizer flags it. Demonstrates pragmatic fixes: reorder fields, use pragma pack to match external layouts, or pad for cache lines. Gives benchmarks: baseline 39.8 ns, unaligned ~80% slower, atomics ~10x slower, atomic unaligned is 5000x slower; padding to 64 bytes avoids false sharing and yields ~33% (or ~12% in a different test) speedups.

AI-written summary · about

  1. 0:00Introduction and music analogy
  2. 4:45Speaker introduction
  3. 5:27C++ alignment rules
  4. 6:10Demo of alignment in C++
  5. 8:41ABI and stack alignment
  6. 9:46Dynamic memory alignment
  7. 11:10Breaking alignment rules
  8. 13:38Alignment in practice
  9. 15:03x86 alignment specifics
  10. 16:49Struct padding example
  11. 17:51Reordering struct members
  12. 18:13Pragma pack for alignment
  13. 19:37SIMD and alignment
  14. 21:00Cache lines and performance
  15. 22:28Benchmarking alignment impact
  16. 24:59False sharing in multithreading
  17. 26:46Bottom line on alignment
  18. 27:52When to use pragma pack
  19. 28:15Summary and conclusion
~/search
type to search 8,222 conferences, 162,397 speakers and 219,688 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
← →
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.