Boost logo

Boost :

From: Richard Damon (rdamon_at_[hidden])
Date: 2002-04-08 08:44:42


> -----Original Message-----
> From: boost-admin_at_[hidden] [mailto:boost-admin_at_[hidden]]On
> Behalf Of James Kanze
> Sent: Monday, April 08, 2002 2:18 AM
> To: boost_at_[hidden]
> Subject: Re: [boost] smart pointer puzzle
>
>
> "Richard Damon \(E-mail\)" <RDamon_at_[hidden]> writes:
>
> |> 2) You need a much smarter shared_ptr that can reconnect to other
> |> copies from the stored pointer, and if there is none to remember
> |> that it does not own it. A normal shared_ptr will not be smart
> |> enough to do this due to the overhead that will be added, as it
> |> requires the keeping of a map of some sort of values under
> |> controlled by all shared_ptrs in the program.
>
> I'm not quite sure what you mean by the first sentence. 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). The
> current boost::shared_ptr doesn't support this, but it is the only
> implementation of reference counted pointers I have encountered that
> doesn't.
>

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.

Boost now has a weak pointer, which works with shared_ptr, which can handle
many of the situations where you want to convert a raw pointer to a
shared_ptr. The equivalent of converting "this" to a smart_ptr is to have
the object store a weak pointer to itself, an when it want to convert "this"
to a smart_ptr it instead converts it weak pointer to a shared_ptr.

> --
> James Kanze mailto:kanze_at_[hidden]
> Conseils en informatique orientée objet/
> Beratung in objektorientierter Datenverarbeitung
> Ziegelhüttenweg 17a, 60598 Frankfurt, Germany Tel. +49(0)179 2607481


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