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.
>
> However there is another problem.
> You have to new your object.
> shared_ptr<MyClass> s( new MyClass );

You can allocate your object however you want:

shared_ptr<MyClass> s(MyClass::allocate(), MyClass::deallocate);

and of course there is also the textbook way of defining a suitable
MyClass::operator new.

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

Leaving aside the issue of whether specializing std::allocator<MyClass> is a
good idea:

shared_ptr< MyClass, MyAllocator > s;

note that you now wouldn't be able to pass s to a function that expects
shared_ptr<MyClass> since the type is not the same.

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

Reply via email to