> Markdown version of [/events/world-congress-2024/sessions/30-an-in-complete-guide](https://www.wearedevelopers.com/events/world-congress-2024/sessions/30-an-in-complete-guide). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # An (In-)Complete Guide to C++ Object Lifetimes - **Date:** Thursday, Jul 18, 2024 - **Time:** 10:10–10:40 (30 min) - **Room:** STAGE 10 (120) - **Event:** World Congress 2024 ## Recording [Watch recording](https://www.wearedevelopers.com/videos/1060-an-in-complete-guide-to-c-object-lifetimes) ## Description A C++ program manipulate objects, but it is undefined behavior if you attempt to manipulate them while they are not alive. So let's do a deep dive into object lifetime. When are objects created and when are they destroyed? How does temporary lifetime extension come into play and what changed there recently? What happens when you `std::malloc` memory and just pretend objects are there without creating anything? Or worse: You use `mmap()` to read shared memory. How do unions interact with constructors, strict aliasing, or the "common initial sequence"? What when you explicitly call the destructor and later re-use the same storage? What's the deal with `std::launder`, `std::bit_cast`, and `std::start_lifetime_as`? We'll answer all of those questions and much more. We'll do that by looking at the C++ standard, old and new proposals, and compiler optimizations. ## Speaker ### [Jonathan Müller](https://www.wearedevelopers.com/@jonathan-muller) Software Engineer ## Related talks at this congress - [I implemented Game of Life 100+ times! Let's explore the 3 most interesting takes...](https://www.wearedevelopers.com/events/world-congress-2024/sessions/331-i-implemented-game) — Ivett Ördög - [Are you done yet? Mastering long-running processes in modern architectures](https://www.wearedevelopers.com/events/world-congress-2024/sessions/303-are-you-done-yet) — Bernd Ruecker - [Why Iterators Got It All Wrong — and what we should use instead](https://www.wearedevelopers.com/events/world-congress-2024/sessions/54-why-iterators-got-it) — Arno Schoedl - [The Lifehacker's Guide to Software Architecture](https://www.wearedevelopers.com/events/world-congress-2024/sessions/269-the-lifehacker-s) — Julian Lang