Boost logo

Boost :

From: Larry Evans (jcampbell3_at_[hidden])
Date: 2003-01-08 14:08:19


Larry Evans wrote:
> Peter Dimov wrote:
> > From: "Larry Evans" <jcampbell3_at_[hidden]>

[snip]
> I'm pretty sure there a reference to it in some of the compare docs
> or code in the files/shared_cyclic_ptr directory.
I thought I'd be more help. The reference is:

David L. Detlefs. "Garbage collection and runtime typing as a C++ library".
In USENIX C++ Conference, Portland, Oregon, August 1992. USENIX Association.

The version in shared_cyclic_ptr uses a static flag (
mk_offsets_descriptor_static::c_subject_start_val() )indicating
whether or not the "internal pointers" are being calculated for a
particular "subject" class. Before this flag is set, memory for an
instance of this subject class is allocated ( in
mk_internal_pointers_descriptor_of<subject> ::CTOR ). The start and
end of this memory are also placed in static variables (Or it should
be). and then placement new is used to create it. Each smart pointer
(or "proxy", to use the shared_cyclic_ptr terminology) as a
prox_record superclass which records the offset of the proxy from the
start of the subject (available from the aforementioned
c_subject_start_val()). These offsets are stored in
mk_internal_pointers_descriptor_of<subject> ::m_ptr_offsets and
subsequently used to find the internal pointers of a subject given the
start address of that subject.

The above paragraph basicly describes Detlef's method. However,
there's a problem with containers, like a vector of proxies. To
handle this, a function for accessing the proxies of the container
(cyclic_count_ip_offset_iterator::mk_proxiter_fun_type) is stored in
the ip descriptor. With scoped_cyclic_container (in
shared_cyclic_ptr.hpp), this avoids problems with most stl-like
containers. John Maddox enountered this problem with his felix gc.
If the definitions of the stl container were modified to specialize
the "root" pointer of the container (e.g. the vector::front or the
head pointer in list) to be a proxy with the prox_record superclass,
then this might be easily added to stl, thus easing the migration to
gc for c++.

> > does it require programmer
> > support?
> >
>
> Yes. It requires declaration of a single static variable for each
> class that's garbage collected. It looks like this:
>
> ip_descriptor_of<test_subj>
> ip_descriptor_of<test_subj>
> ::c_mk_descriptor
> ;

At least in my latest incantation of my gc code. However, in the
shared_cyclic_ptr directory, this appears as:

boost::mk_internal_pointers_descriptor_of
   <subj_top
     <boost::cyclic_count_gc
       <boost:: GC_METHOD, boost::ip_offset_iterator
>
>
>::
   c_my_type
     ;

in the iplimits.cpp file.


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