C++ Under the Hood: Internal Class Mechanisms
summary
Shows how polymorphism really maps to memory: compilers put a single vptr at offset 0 and one shared vtable per most-derived class, so virtual dispatch costs about one extra pointer per instance. Explains construction/destruction order precisely — inside-out construction, outside-in destruction — and why ctors and dtors write vptrs to ensure safe virtual calls. Demonstrates multiple-inheritance this-pointer adjustments, pointer-to-member data as offsets (null representation varies), global/static-init ordering, and concrete UB from calling methods on not-yet-constructed globals.
AI-written summary · about
chapters (17)
- 0:00Introduction to C++ internals
- 1:54Object memory footprints
- 3:17Vtables and polymorphism
- 8:44Construction order in inheritance
- 10:56Inheritance and construction principles
- 13:25Constructor initialization lists
- 20:36Virtual functions and destructors
- 22:25Destruction order and vtable safety
- 28:29Global object construction
- 33:16Static variables in member functions
- 37:56Array construction and destruction
- 43:19Static memory destruction order
- 45:05State machines in global objects
- 47:40Pointers to functions in C++
- 50:11Pointers to member functions
- 52:42Pointer to member data
- 58:07Q&A and closing remarks
