Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Thanks for this answer! That's a good point that level creation and destruction is rare, so the overhead will be very small. And shared pointers are probably already optimized a ton so it will barely matter. Commented Sep 6, 2020 at 16:30
  • Nice overview of different strategies and tradeoffs. Commented Sep 6, 2020 at 17:05
  • 1
    @BakedPotato well, there's a bit of memory overhead from shared ptrs that I didn't go into. But that shouldn't matter in most cases. The important part is that you only store the game objects as shared ptrs, but your other code can use shared_ptr::get() and use them as raw pointers as before. Commented Sep 6, 2020 at 17:23
  • Also w.r.t. overhead, if you create the pointer with make_shared the heap/memory overhead is reduced too - both space and time. Commented Sep 7, 2020 at 1:09