[Gc] Re: C++ API enhancement proposal
Larry Evans
cppljevans at cox-internet.com
Mon Oct 15 08:04:42 PDT 2007
On 10/15/07 08:45, skaller wrote:
> On Mon, 2007-10-15 at 07:02 -0500, Larry Evans wrote:
>> On 05/11/07 13:18, skaller wrote:
>> [snip]
>>> BTW: you might look at how Felix does this. The call for gc object
>>> construction is:
>>>
>>> new (gc, shape<X>) X(args)
>>>
>>>
>>> Here 'gc' is the collector, and 'shape<X>' is the data needed by the
>>> collector to find the pointers in an X.
[snip]
>> So in Felix, is shape<X> determined by the compiler? I've not
>> heard of a c++ compiler which provides this.
>
> Yes, it's provided by the compiler.
>
> I believe there is a hook for walking some data structures
> for boehm gc, but haven't spotted it yet. Can this be done?
> i.e. make bdrgc more precise?
Yes, according to the sentence:
Some may have per-object type descriptors that determine pointer
locations.
in:
https://www.hpl.hp.com/personal/Hans_Boehm/gc/gcdescr.html
A sortof template for these descriptors, I believe, are located
in the source file, gc_typed.h. There's also this:
https://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gc_typedh.txt
FWIW, I tried to understand and use this, but decided it was easier
to define a descriptor as just a function pointer which, given an
ptr to an object of the type, produced an iterator over all the pointers
contained in the object of that type. IOW, something like boost's
visit_each:
https://www.boost.org/doc/html/signals/reference.html#header.boost.visit_each.hpp
For all stl collections, X, this function just returned X.begin. For
structs and classes, I had to calculate the offset of each pointer
(I had to use smart ptrs to do this and the smart_ptr CTOR recorded the
offset) from the start using Detlef's method, detl[92] on:
https://www.cs.kent.ac.uk/people/staff/rej/gcbib/gcbibD.html
I wasn't thrilled with this method of calculating offsets;
however, the method of recording the information after the offsets
are calculated might be a useful alternative to that described
in gc_typed.h since it could be used for collections (e.g. std::vector,
and std::list) also (just use a different function to produce the
iterator).
>
> I also heard a bitmap can be supplied, but that won't
> work for arrays .. as I discovered variable length arrays
> require direct support in the gc.
>
More information about the Gc
mailing list