A Deep Dive Into C++ Object Lifetimes - Jonathan Müller - C++Now 2024

  Рет қаралды 4,551

CppNow

CppNow

Күн бұрын

Пікірлер: 9
@zlatkogjuroski3235
@zlatkogjuroski3235 Ай бұрын
Great talk!
@N....
@N.... Ай бұрын
Great talk, I hadn't thought about the concept of pointer provenance before but it makes a lot of things click together now that just seemed like strange rules previously.
@sqlexp
@sqlexp Ай бұрын
What if the constructor throws an exception in placement new when you reuse a pre-existing variable after calling std::destroy_at? Then the variable is not constructed and the destuctor will be called on a non-constructed storage😱 This isn't an exception-safe practice. Only use placement new on storage where the call to destructor isn't inevitable or the constructor is noexcept.
@Roibarkan
@Roibarkan 25 күн бұрын
31:51 🤓 this code also needs to verify that (this != &other)
@CybeleNode
@CybeleNode Ай бұрын
Pre compile time and run time objs
@AlfredoCorrea
@AlfredoCorrea Ай бұрын
44:19 so, if I have a data structure with its values *scattered* across a single allocation, does it make sense do a (complicated) loop to start_lifetime_as for each of the value elements? I don’t mind doing it if the loop(s) is elided anyway, and if it improves the correctness of the code (i doubt the compiler will see into that much logic anyway to make my objects blessed, but ok). I could do a start_lifetime_as_array for the whole allocation but that seems an overkill too because not all memory will be having usable objects. Great talk!
@foonathan
@foonathan Ай бұрын
Thanks! You don't necessarily need to call start_lifetime_as in a loop before, can't you just do it the first time you access the element? Unless you don't know when that happens. Alternatively, just calling start_lifetime_as_array is fine, it doesn't actually "do" anything, and it doesn't matter if you start the lifetime of types that aren't actual objects - they just have indeterminate values.
@AlfredoCorrea
@AlfredoCorrea Ай бұрын
@@foonathan I think I am confused, this is for a container that doesn't initialize elements (doesn't do any work) if the default constructor is trivial. In the past, what is I did is to simply allocate (allocator.allocate) and then don't run any code in this memory in the constructor. Then I realized that I should at least start the lifetime. start_lifetime_as is an option I guess, but what I really need is that uninitialized_default_construct, but I also have to hope(?) that it compiles to nothing for trivial constructors. What was attractive of start_lifetime_as is that it wouldn't add any machine code.
@Roibarkan
@Roibarkan 3 ай бұрын
12:24 kzbin.info/www/bejne/bHayhIWBgr52isU
ЗНАЛИ? ТОЛЬКО ОАЭ 🤫
00:13
Сам себе сушист
Рет қаралды 4 МЛН
Triple kill😹
00:18
GG Animation
Рет қаралды 17 МЛН
MAGIC TIME ​⁠@Whoispelagheya
00:28
MasomkaMagic
Рет қаралды 38 МЛН
I tricked MrBeast into giving me his channel
00:58
Jesser
Рет қаралды 28 МЛН
Is C++ better than C?
1:46:10
Tsoding Daily
Рет қаралды 49 М.
CppCon 2018: Jason Turner “Surprises in Object Lifetime”
1:01:28
C++26 Preview - Jeffrey Garland - C++Now 2024
1:26:28
CppNow
Рет қаралды 10 М.
Why Isn't Functional Programming the Norm? - Richard Feldman
46:09
Global Variables in C++... not as easy as it seems
18:25
The Cherno
Рет қаралды 65 М.
ЗНАЛИ? ТОЛЬКО ОАЭ 🤫
00:13
Сам себе сушист
Рет қаралды 4 МЛН