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.

12
  • std::allocate_shared lets you set an allocator so you can allocate however you want, you don't have to use the heap. Commented Jun 20, 2018 at 22:23
  • 1
    I don't really think there are many benefits, but I was wondering if it would be frowned upon for whatever reason I am not aware of to use std::shared_ptr. My resource does not need to be allocated on the heap Commented Jun 20, 2018 at 22:40
  • 2
    It's pretty routine to use unique_ptr and shared_ptr for resources other than heap allocations. Commented Jun 20, 2018 at 22:59
  • 4
    I'm more concerned about why you want shared ownership of a shader. Are you sure you want that? Because most graphics systems are sufficiently rigid that you don't just leave shaders lying around and truly owned by multiple users. They're resources, like textures, and you want their lifetimes to be controlled by a resource manager, not by how many objects in the scene use them. And if the resource manager is destroyed, then you should no longer be using the object; if you are, that represents a logic error. Commented Jun 20, 2018 at 23:53
  • 1
    @NicolBolas Or you want the shader to hang around as long as something needs it and automatically be cleaned up when nothing references it any more. The simplest form of resource manager. Commented Jun 21, 2018 at 1:50