Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-04-17 15:43:01


Scott Maxwell wrote:
>> This is what intrusive_ptr is for. Just define intrusive_ptr_add_ref
>> and intrusive_ptr_release for your count class.
>
> Unless I have missed something, intrusive_ptr has the following
> issues:
>
> 1. You must declare intrusive_ptr_add_ref and intrusive_ptr_release as
> top-level functions that take a pointer to your class. This can be
> problematic if your client class is a nested private class as in my
> prior example.
>
> 2. You must define the functionality of those two functions. While
> the functionality is trivial, it still needs to be done manually for
> each
> class. Anything manual is subject to error.
>
> The shared_ptr_embedded and shared_ptr_count pair solve both issues.

No, you only need to implement the addref/release functions for the base
class. See libs/smart_ptr/test/intrusive_ptr_test.cpp for an example.

A future boost release will probably contain such a base class. I didn't
want to introduce one at this time since it may have created confusion, as
1.29 had boost::counted_base that was automatically recognized by
shared_ptr. In 1.30 shared_ptr no longer supports intrusive counting.


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