Taking a Byte Out of C++ - Avoiding Punning by Starting Lifetimes
summary
Claim: C++23 introduces start_lifetime_as to explicitly begin object lifetimes so bytes can back objects without UB from type punning. Shows concrete implementations: memcopy into an aligned byte buffer, a std::like STD bitcast implemented in portable C++20 style, careful use of std::launder, and an expected‑returning API plus Concepts for validation. Applied to a time‑series DB to achieve zero copy page mapping, variable‑length updates, and audited, reusable lifetime‑starting helpers.
AI-written summary · about
chapters (6)
- 0:00Start
- 5:42No Type Punning
- 10:36C++ Types May Have Invariants
- 12:30Implicit-Lifetime Types (C++20)
- 30:55Ending an Object's Lifetime
- 40:17Summary
related talks
35mAn (In-)Complete Guide To C++ Object Lifetimes
01h 00mAn (In-) Complete Guide to C++ Object Lifetimes
58mLeveraging C++20/23 Features for Low Level Interactions
01h 01mC++ Object Lifetime: From Start to Finish
01h 01mEmbracing PODs Safely Until They Die
01h 02mEmbedded Friendly C++: Features That Make a Difference
01h 03mLifetime Safety in C++: Past, Present and Future
01h 05mC++11 in the Wild: Techniques from a Real Codebase
