Boost logo

Boost :

From: Michael Goldshteyn (mgoldshteyn_at_[hidden])
Date: 2005-11-14 11:08:53


"Peter Dimov" <pdimov_at_[hidden]> wrote in message
news:002801c5e56a$a6d88930$6401a8c0_at_pdimov2...
> Michael Schneider wrote:
>
>> Is there a reason why shred_ptr does not accept an allocator?
>
> shared_ptr doesn't have an allocator template parameter because this would
> encode an implementation detail into its type. An important design
> principle
> of shared_ptr<T> is to hide such specific requirements behind an opaque
> type
> that just "does the right thing" when it comes to
> deallocation/destruction.
>
> This doesn't mean that shared_ptr shouldn't accept an allocator, though.
> The
> proper way to add allocator support would be via an additional
> constructor:
>
> template<class Y, class D, class A> shared_ptr( Y * p, D d, A a );
>
> and a corresponding reset.
>
> Now in CVS. ;-)
>
>> - If a change is required, what can I do to help make this change
>> in boost (I am new to the boost community)?
>
> You can contribute a test for the new functionality. :-)

I don't understand. Looking at sp_counted_impl.hpp, it appears that there
already is a way to do this in the current shared_ptr implementation, using
the following steps:

- Define BOOST_SP_USE_QUICK_ALLOCATOR
- Make sure BOOST_SP_USE_STD_ALLOCATOR is not defined
- Create an instance of the quick_allocator class template for the class you
are using with shared_ptr, redefining the quick_allocator instatiation's
alloc and dealloc functions as needed

Am I wrong in my interpretation of that code? I will acknowledge, however,
that your approach above, with the three parameter constructor, is the more
proper way to add a custom allocator.

Michael Goldshteyn


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk