samedi 27 juin 2015

Is an Object Pool pattern of shared_ptr possible?

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:

  1. 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.

  2. 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