Boost logo

Boost :

From: David B. Held (dheld_at_[hidden])
Date: 2002-06-19 04:10:32


"Markus Schöpflin" <markus.schoepflin_at_[hidden]> wrote in message
news:3D1045AC.7D58D070_at_ginit-technology.com...
> [...]
> BTW, is there any documentation on using the intrusive features of
> the new shared_ptr? Or isn't it supposed to be used outside the
> implementation?

I think right now the code is the documentation. ;) The intrusive
features were created to support intrusive_ptr, which allows you
to derive a class from boost::counted_base, which stores the
count with your object, instead of externally. You can create a
shared_ptr from an intrusive_ptr (it will automagically use the
intrusive count).

That pretty much tells you what you need to know to use it (and
you can always look at the code if you're not sure about something...
the intrusive pointer is pretty short and straightforward).

Here's an example:

class foo : boost::counted_base
{
...
    bar();
};

{
    boost::intrusive_ptr<foo> p(new foo);
    // count is 1
    p->bar();
    {
        boost::shared_ptr<foo> q(p);
        // count is 2
        q->bar();
    }
    // count is 1
}
// count is 0, foo destroyed

Dave


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