Boost logo

Boost :

From: Dave Harris (brangdon_at_[hidden])
Date: 2002-04-08 16:46:19


In-Reply-To: <KBEEJNHPFAMCGLNKDFEFOEOBDEAA.rdamon_at_[hidden]>
On Mon, 8 Apr 2002 09:44:42 -0400 Richard Damon (rdamon_at_[hidden])
wrote:
> > In general, to be useful, you must be able to create a smart
> > pointer from a raw pointer multiple times (or find some way of
> > making "this" a smart pointer).
>
> To my experience most *non-invasive* smart pointers have this
> limitation. An invasive smart pointer put the shared state in the
> object making it easy to adopt a raw pointer. A non-invasive
> pointer gets no such help from the object, to convert the raw
> pointer into a shared pointer normally requires a map of some
> sort, which makes the implementation much more heavy weight. I
> will agree that most smart pointers I have seen where invasive, this are
> much easier to write, but I understand Boosts decision to go
> non-invasive, there are times when invasive is not an option.

I gather some clever people have recently figured out a compile-time test
for a class member. We could use this to write a smart pointer which has
an invasive specialisation for classes which inherit from
boost::ref_counted, and which defaults to a std::map non-invasive
implementation otherwise.

Currently I don't use the boost pointer, mainly because of the problems
with multiple counts. Efficiency is another concern: invasive smart
pointers tend to be a lot more efficient than non-invasive ones. I think I
would use a boost pointer like the above, though.

-- Dave Harris


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