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

Поділитися
Вставка

КОМЕНТАРІ • 9

  • @zlatkogjuroski3235
    @zlatkogjuroski3235 2 місяці тому

    Great talk!

  • @N....
    @N.... 2 місяці тому

    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.

  • @AlfredoCorrea
    @AlfredoCorrea 2 місяці тому

    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 2 місяці тому

      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 2 місяці тому

      @@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.

  • @CybeleNode
    @CybeleNode 2 місяці тому

    Pre compile time
    and run time objs

  • @Roibarkan
    @Roibarkan Місяць тому

    31:51 🤓 this code also needs to verify that (this != &other)

  • @Roibarkan
    @Roibarkan 4 місяці тому +1

    12:24 ua-cam.com/video/6EOSRKMYCTc/v-deo.html