On Tuesday, Aug 26, 2003, at 10:41 America/Denver, E. Gladyshev wrote:
--- Gregory Colvin <[EMAIL PROTECTED]> wrote:
For shared_ptr the count is allocated by the following line in the
shared_count
constructor:

new sp_counted_base_impl<P, D>(p, d);

So it might be possible to make the allocation customizable by
specializing
sp_counted_base_impl.

I think it would be great.

Then I suggest giving it a try.


However there is another problem.
You have to new your object.
shared_ptr<MyClass> s( new MyClass );

You cannot use allocator like you would expect:
shared_ptr< MyClass, std::allocator<MyClass> > s;

Right. The shared_ptr design carefully avoids any extra class template parameters, in favor of parameterizing the constructor.

My idea, if it works, would be to specialize sp_counted_base_impl
on the pointer type P, e.g. MyClass*, so you just write

shared_ptr<MyClass> s( new MyClass );

or on the deleter type D, so you would write, e.g.

shared_ptr<MyClass> s( new MyClass, MyDeleter<MyAllocator<MyClass>> );

The idea is that your sp_counted_base_impl specialization provides
a custom operator new and operator delete that uses your allocator.

Alternatively, we could consider adding shared_ptr constructor that
takes an allocator argument.


_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to