samedi 20 février 2021

How to re-cycle the Control Block allocated for std::shared_ptr

std::shared_ptr internally allocates(::new) a Control Block(Reference Count Object) in heap. When shared ptr's reference count becomes zero this Control block is deallocated(::delete). For Performance reasons I need to re-cycle the memory allocated for this Control Block.

Accepted answer to Question Is an Object Pool pattern of shared_ptr possible?, says a Custom Allocator should do the trick. But it is NOT clear to me how the Allocator (Alloc) object created for Y does the allocation for Control Block

template< class Y, class Deleter, class Alloc > std::shared_ptr( Y* ptr, Deleter d, Alloc alloc );

Could someone please point to an example of a custom allocator written for std::shared_ptr which re-cycles the Control Block object

OR

provide a partial code to re-cycle Control Block

OR

explain how an Allocator<Y> can allocate the Control Block for std::shared_ptr template< class Y, class Deleter, class Alloc >

NOTE : I am looking for a Solution that does NOT use boost::intrusive_ptr

Aucun commentaire:

Enregistrer un commentaire