Class Layout
summary
Shows concrete rules and experiments: use offsetof and compiler dumps (GCC/clang/MSVC flags, Godbolt) to see real offsets; C++11 loosens block ordering and C++23 mandates declaration order; apply no_unique_address or rely on EBCO to collapse empty members; composition can make an object 12 bytes versus 8 bytes — a 50% size difference — and microbenchmarks (Google Benchmark, 100 iterations, sizes 100..1e6) find layout-dependent timing with spikes and sometimes up to 4x speed differences for accumulate while results remain platform dependent and inconclusive.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 1:48Class layout in C++
- 3:35C++ standard layout rules
- 10:27Subobjects and layout
- 13:18Alignment requirements
- 17:01Inheritance vs composition
- 23:05Empty base class optimization
- 27:01Standard layout types
- 31:38Inspecting layout with compiler flags
- 39:17Performance impact of layout
- 49:00Q&A
related talks
52mNon-conforming C++: the Secrets the Committee Is Hiding From You
01h 26mC++ Under the Hood: (Internal Class Mechanisms)
01h 30mTuning C++: Benchmarks, and CPUs, and Compilers! Oh My!
01h 28mProgramming in Modern C with a Sneak Peek into C23
59mSoftware Engineering Is About Tradeoffs
01h 22mThese 10 tricks that only library implementors know!
01h 00mMoving Faster: Everyday efficiency in modern C++
57mC++ MythBusters Strike 2
