Thomas
Thomas

Reputation: 55

Do I need custom allocators for shared pointers?

If I override operator new and operator delete (or passing a custom deleter), what use is passing an allocator? Will the shared_ptr at some other time than construction and deconstruction do allocations and deallocations?

Upvotes: 4

Views: 271

Answers (1)

Salgar
Salgar

Reputation: 7775

The allocator passed into a boost::shared_ptr is used to allocate the internal details of the shared pointer (The shared/weak reference counts) and has nothing to do with the object passed in, which you will have already allocated, as you pointed out.

Here is another answer on the subject: Boost shared_ptr: How to use custom deleters and allocators

Upvotes: 1

Related Questions