Re: Smart pointer libraries other than Boost?
On Mar 3, 8:43 am, mcz...@poczta.onet.pl wrote:
- one pointer having ownership, many others just "observing"
That's tricky. The problem is that you don't know where the
other pointers are, so you don't know how to eliminate them.
I have a ManagedPtr class which does this, and boost has its
weak pointers, but in practice, I rarely find either to be
useful. Both just null the "observing" pointer---they don't
remove it from a container, if that's where it, and they
don't tell the owner of the "observing" pointer that it now
has to look for a back up solution.
I will know where the other pointers are - these will be not
not trackable T*, but special trackable ref<T>.
You'll know the address of the other pointers, but you still
won't know where they are, e.g. in an std::set or an
std::vector, for example.
I think it is good idea to have two reference counters - one
for owning pointers, second (in debugging mode) for observing
pointers.
That's the usual solution in this case. In practice, I've not
found such pointers very useful, however.
- explicit ownership passing instead of the destructible
copy for type of pointers with only one owner
That sounds a bit like std::auto_ptr. Of all the smart pointers
at my disposition, it's definitely the one I use the most.
So do I, but auto_ptr does use the destructible copying,
which I do not like, as it makes code counter intuitive.
Yes. It's really only for special cases (like passing the
object to another thread). But most of the other cases are
handled directly with raw pointers.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34