A TODO for somebody: Full Reflection Gets You Smarter GC

Steve Horne stephenwantshornenospam100 at aol.com
Fri Nov 24 21:07:18 PST 2006


On Mon, 20 Nov 2006 17:49:32 -0700, Russ Lewis
<spamhole-2001-07-16 at deming-os.org> wrote:

>It is possible to have a smarter GC using compile-time reflection.

I have a related idea that basically the programmer should be able to
customise the garbage collection process for certain classes.

For example, there is a method that can be used for getting
doubly-linked list behaviour from a singly linked list. The idea is
that an iterator holds pointers to two adjacent items in the list, and
that the link item holds the xor of the pointers to the previous and
next items.

With this approach, it is always possible to do a step forwards or
backwards. But there are no actual pointers to most of the items in
the list - only those referenced by any current iterators and the
first and last items (held as part of the list-as-a-whole object).

You wouldn't use this data structure without some kind of custom
allocators anyway, since saving that one pointers worth of space is
pointless unless you also deal with heap allocation overheads, but
depending on how you handle the custom allocation you may still rely
on those links to indicate which custom-allocated blocks have still
got valid items in them. And that suggests that you might want to
inject something into the GC that can follow through the list
step-by-step using the calculated pointers, ensuring that all
currently used blocks get marked.

A standard overridable method (in the list-as-a-whole class) would
probably be able to do the trick. And the same approach could be used
(in a few heavily instantiated or otherwise problematic classes) to
restrict the part of the object that is checked for pointers.

Theres probably an efficiency issue, though.

-- 
Remove 'wants' and 'nospam' from e-mail.



More information about the Digitalmars-d mailing list