Timeline for Implementing reference counting from scratch or using shared_ptr for resource?
Current License: CC BY-SA 4.0
18 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 26, 2018 at 8:38 | answer | added | Richard Hodges | timeline score: -1 | |
| Jun 21, 2018 at 16:11 | comment | added | Nicol Bolas |
@immibis: What I'm saying is that it is a bad form of "managing resources", one that does not actually represent the logical ownership relationships between the objects. If a level loads a model, and the level loads a shader, and that shader gets used with that model, if the level is unloaded, both the model and the shader ought to go away. That's the logical relationship here. Shared pointers make it possible to prevent this by having something else take ownership of them. My question is why you would want that, and whether such transfers of ownership are worth the costs of shared_ptr.
|
|
| Jun 21, 2018 at 14:57 | vote | accept | Anonymous Person | ||
| Jun 21, 2018 at 11:41 | history | tweeted | twitter.com/StackSoftEng/status/1009763197962858496 | ||
| Jun 21, 2018 at 3:53 | comment | added | Stack Exchange Broke The Law | Then the shared_ptr system is managing resources. The level is not managing resources, rather the shared_ptr system is saying "oh, this level is still around, i shouldn't free this shader". And if you have multiple shaders per model, well, something in the rendering pipeline has to know about all the shaders, so it should have references to all the shaders. | |
| Jun 21, 2018 at 1:55 | comment | added | Nicol Bolas | @immibis: Then this "level" is acting as a resource manager, and therefore there is no need for "model" objects to be able to exist independently of a "level" or some other object that owns them. Also, associating "model" with "shader" is just bad design. You might render the same model with various kinds of shaders: regular shaders, shadow rendering shaders, depth pre-pass shaders, etc. | |
| Jun 21, 2018 at 1:53 | comment | added | Stack Exchange Broke The Law | @NicolBolas As I said, the simplest form of resource manager. And it might not be only the object that references the shader, the model might have a reference to the shader and the level might have a reference to the models of objects that spawn in that level. | |
| Jun 21, 2018 at 1:52 | comment | added | Nicol Bolas | @immibis: OK, so who gave that something a reference to the shader? If a new object is spawned that needs that shader, will you go and reload it? Or would it be better to have a resource manager that isn't quite so simple? | |
| Jun 21, 2018 at 1:50 | comment | added | Stack Exchange Broke The Law | @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. | |
| Jun 21, 2018 at 1:10 | answer | added | Nicol Bolas | timeline score: 8 | |
| Jun 21, 2018 at 0:08 | comment | added | Deduplicator | @JerryCoffin: Gets a bit difficult if you have some non-pointer handle-type though, especially if you cannot safely round-trip-convert it through some pointer type. | |
| Jun 20, 2018 at 23:53 | comment | added | Nicol Bolas | 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. | |
| Jun 20, 2018 at 22:59 | comment | added | Jerry Coffin |
It's pretty routine to use unique_ptr and shared_ptr for resources other than heap allocations.
|
|
| Jun 20, 2018 at 22:40 | comment | added | Anonymous Person | 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 | |
| Jun 20, 2018 at 22:35 | comment | added | Blrfl | What benefit do you see in re-implementing it from scratch? | |
| Jun 20, 2018 at 22:23 | comment | added | esoterik | std::allocate_shared lets you set an allocator so you can allocate however you want, you don't have to use the heap. | |
| Jun 20, 2018 at 22:06 | review | First posts | |||
| Jun 21, 2018 at 8:55 | |||||
| Jun 20, 2018 at 22:05 | history | asked | Anonymous Person | CC BY-SA 4.0 |