Boost logo

Boost :

From: Jarrad Waterloo (jwaterloo_at_[hidden])
Date: 2007-04-10 13:04:29


I am very interested in such a family of smart pointers as I deeply believe
that weak_ptr isn't a real solution to cyclical references as your scenario
illustrates.
Some questions if you don't mind.
Will resources be cleaned up in a deterministic manner ie. When the last
master of A or B is deleted on the stack will it immediately cleanup A and
B? If that is not the case, is there a gc_cleanup() method that would have
to be called in code or in a background thread?
Can it handle object graphs of arbitrary/any complexity or does it only work
with hierarchies?

Please don't keep me, the boost user community, waiting.

-----Original Message-----
From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]]
On Behalf Of Ariane van der Steldt
Sent: Tuesday, April 10, 2007 1:35 AM
To: boost_at_[hidden]
Subject: [boost] interest poll: smart pointers that handle
circularreferences

Hello,

I was wondering if there's interest in a smart pointer, which is able to
cope with circular references. I think it would make a nice addition to
the smart_ptr classes already in boost.

I have a library almost ready, which can solve the problem where:
- class A contains a pointer to class B
- class B contains a pointer to class A
- and it is not known wether the "master" of these two is A or B.

With "master", I mean which pointer is the pointer that is kept alive
from the execution thread. For example, if we would implement this with
shared_ptr and weak_ptr, we would most likely have the following:
- class A contains a shared_ptr to class B
- class B contains a weak_ptr to class A
- the execution thread contains a shared_ptr Ptr to class A.
In this case, if I where to assign Ptr = B, A would be erased, since A
no longer is referenced (weak_ptr references don't count
reference-counter wise).

The code I have aims to solve this problem, by using two types of
pointers. The execution thread will work with boost::intrusive_ptr
(which are allocated on the stack) while classes wishing to point to
other classes, will use a new type of pointer (named 'reference') that I
designed. This pointer is aware of the owner of the pointer, in addition
of the object it points to.

The implementation uses only standard C++ code, with some help from
boost (notably boost::intrusive_ptr and, in the case of multithreading
environments, boost::thread).

Anyways, I am wondering if people are interested. :) Can't imagine that
it wouldn't be of use to at least some of you. ;)

For status info: I am currently ironing out some minor bugs and
implementing STL-type collection classes (like the equivalent of a
std::list<MyClass*> ) for these pointers, as they have non-standard
initialization semantics.

Ariane

_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost


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