Is it possible to create an Object Pool of shared_ptr? Sketching this in my head, I can see two ways of doing this but each have a flaw:
-
If T objects were stored in a reusable pool, the act of wrapping T in a shared_ptr on a get() request would result in the control block being re-allocated on the heap each time - therefore breaking the concept of an Object Pool.
-
If shared_ptr objects were stored in a reusable pool, the shared_ptr object must stop existing to initiate a custom deleter, and the custom deleter function only gets called with a T pointer. So there is nothing to recycle.
Aucun commentaire:
Enregistrer un commentaire