From: Larry Evans (jcampbell3_at_[hidden])
Date: 2002-03-27 10:26:27
"Schoenborn, Oliver" wrote:
> I needed a smart pointer that works for stuff that auto_ptr was not meant to
> do, and that shared_ptr was not meant to do either: a pointer owner (as
> opposed to an owned pointer) that is in charge of deep copy and deletion
> when owner goes out of scope, coupled with a pointer user that only provides
> pure shared usage (no ownership) tied to an owner.
Except for the "deep copy" feature, the prox_own_btm and prox_use_btm
classes in http://groups.yahoo.com/group/boost/files/2001/GarbageCollectByTmplSpecializa/
seem to fit your requirements. This pair also will throw when a prox_use_btm
smart pointer accesses a pointer(or "subject" in the Gof4 terminology) whose
prox_own_btm goes out-of-scope. In addition, an exception is thrown when
a cycle is formed in the prox_own_btm instances. This is, of course, more than you
want, but it would be easy to remove. The main problem, I think, is that the code
is pretty hard to understand and it has several template specializations which MSVC++
doesn't handle. However, it does work with g++2.95.X or there-abouts.
> This provides for a nice separation of roles and responsibilities, since
> often an object is created in one place and not used, but given to another
> object for usage but not management. An owned pointer is provided that
> brings the two together for the cases where this is necessary.
> I haven't seen anything else like it anywhere. It's clean, standard code,
The orginal motivation for prox_own_btm and prox_use_btm was the
LiveWrapper and RefWrapper classes in polaris( See
However, polaris can't collect cycles in the LiveWrapper graph and uses refcounts in each
element of the the list structure; consequently, there is much more memory used for
I'm currently trying to understand jam in order to upload a version of shared_ptr
which is simpler and easier to compare different methods of iterating over the
internal points (an "ip_iterator" class) of a subject. This ip_iterator class is only
useful for detecting cycles; so, you may not be interested in that either.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk