Mathieu Ropert: Heaps Don't Lie - Guidelines for Memory Allocation in C++

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 พ.ย. 2024

ความคิดเห็น • 14

  • @antoniocoratelli
    @antoniocoratelli หลายเดือนก่อน +8

    Best talk title ever

  • @saniel2748
    @saniel2748 หลายเดือนก่อน

    Great talk, thanks for sharing

  • @ajcosta
    @ajcosta หลายเดือนก่อน +2

    Good talk :)! I think there was one point about stack allocation that is important but is not mentioned: stack allocation does not let you share memory with other threads.
    A stack is by definition associated with a thread. If that thread allocates something on the stack, it can't share that memory with other threads.
    Actually, it can but that memory may disappear "anytime" so if you do that you are just introducing a terrible bug.
    That is one thing that you can't use stack allocation for (but you can use the stack-like custom allocator mentioned).

    • @atijohn8135
      @atijohn8135 หลายเดือนก่อน +1

      Well yeah, but you can make the same mistake with malloc, this is just freeing the shared memory too early. There's nothing wrong with using the stack for shared memory if allocating it in the main thread and joining all the threads at the end of the same function for example.

  • @mirrorless_mirror
    @mirrorless_mirror หลายเดือนก่อน +1

    Actually, on Windows, MS CRT malloc() just calls HeapAlloc(). It was doing some magic back in the days of the Visual C++ 6, but later on it has became just a tiny wrapper of the HeapAlloc().

  • @12affes
    @12affes หลายเดือนก่อน +1

    For #6 you could also use a callback and avoid any allocations and redundant reserves(), ie.
    find_neighbours( current, [&](Point p) { ... } );

  • @berndeckenfels
    @berndeckenfels หลายเดือนก่อน

    Instead of output parameters you can use an arena

  • @mytech6779
    @mytech6779 หลายเดือนก่อน +1

    Very good.

  • @countsudoku2
    @countsudoku2 หลายเดือนก่อน +3

    The monotonic allocator talk that is mentioned in this talk is most probable th-cam.com/video/IGtKstxNe14/w-d-xo.html

  • @andersama2215
    @andersama2215 หลายเดือนก่อน

    Right you can't pop on a monotonic allocator, it's in the name. Monotonic refers to the strictly increasing behavior of the pointer, that pointer being something to that's "free", when you "free" you don't do anything until the allocator needs to go, or you know you can clear the allocator entirely. However, if you drop the simplicity of the monotonic behavior, with a bit a bookmarking you can let's say keep track of more than one pointer etc, allowing you to pop a fixed number of times. The trick at that point is understanding how your application / algorithm works in terms of allocation, do you have a structure or data that is stack-like that tends to grow larger and larger over time/use anyway? Probably a better fit than a monotonic allocator.

  • @norton7715
    @norton7715 หลายเดือนก่อน

    You can use aggregate initialization instead, to avoid the free:
    void clear()
    {
    *this = {};
    }

  • @zanagi
    @zanagi หลายเดือนก่อน

    that title lmao

  • @FrancoVS2112
    @FrancoVS2112 หลายเดือนก่อน

    Slides froze at 20:30

    • @SwedenCpp
      @SwedenCpp  หลายเดือนก่อน +3

      Yes, only for a few seconds. Unfortunately, there's nothing I can do about it due to an issue with the slide recording, but you shouldn't miss any important content.