Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2005-06-07 05:08:54

On 06/07/2005 01:43 AM, Lorenzo Bettini wrote:
> I solved the problem in a (probably) not too elegant way: when I know
> that I'm creating objects with mutual dependences say A and B I store
> weak pointers, and I store a shared pointer to A and B into a list. As
> long as the list survives the weak pointers are still valid. When I
> want to deallocate everything, all I have to do is to deallocate the
> list. This worked, and also valgrind says there are no leaks...
Well, I see how this solution will work for any graph because any graph
can be represented by G=(V,A) where V is the set of vertices,
and A, the directed edges (or arcs) is VxV; so, as long as you keep
shared_ptr<v> for each v in A, and all the A's are weak_ptr's,
then dereferencing an A will be valid. The question is, "is this
practical?" The extra cost, is of course, V.size * size(shared_ptr<v>).
Maybe this is what Le Chaud had in mind when he said "if containers are
heavily employed" in one of his posts to comp.lang.c++.moderated.

Boost list run by bdawes at, gregod at, cpdaniel at, john at