Boost logo

Boost :

From: John Max Skaller (skaller_at_[hidden])
Date: 2001-05-24 22:04:02


Larry Evans wrote:

> Felix will work if each dynamically allocated
> piece of memory to be garbage collected has an appropriate frame_t
> tacked onto the front by the allocator. Right?

        Well, it is probably trickier than that, but the idea is
roughly correct :-)

>For example, if the link struct is:
> struct link{ link*pre,suc;void*data};
> then the frame_t offsets for link would point to pre,suc,and data where pre is the
> predecessor node, suc is the succesor node, and data actually points to a T.
> Then the allocator would have to allocate these link nodes with such an offset.
>
> For this to work WITHOUT refcount'ed smart pointers, the list<T*>::pre and suc
> would have to be designated as root pointers if a list<T*> were on the stack.

        It will not work UNLESS the first and last elements
of the list do NOT point at the on-stack list head object.
Assuming they do not, then the on-stack pointers must be
roots at the point the collector is called.

        If one uses flx_gc smart pointers, and NO roots,
everything will work fine provided the collector isn't called
(until after the list isn't needed). Calling the collector
will (usually) delete all the list nodes (except the one
on the stack). Unlinking a node should cause the node
to be deleted immediately (since its refcount will go
to 0).

        Note that if the head node points to a circular list
refcounting will NOT delete the list just when the pre and
suc pointers of the head node are cleared. But the list
will be deleted when the collector is called.

-- 
John (Max) Skaller, mailto:skaller_at_[hidden]
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net

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