On 5/12/14, 10:25 AM, bearophile wrote:
Walter Bright:

Unions of pointers are so rare in actual code that treating them
conservatively is not a big problem.

std.variant.Algebraic is based on on std.variant.VariantN, and on
std.variant.VariantN is based on an union, and often you use algebraic
data types to represent trees and similar data structures that contain
many references/pointers. Adding Adding an onGC() method to
std.variant.VariantN you allow the GC to manage Algebraic well enough.

I, too, felt the need of onGC() - actually preGC() - in my allocators implementation.

Specifically, a thread-local freelist would save a pointer to the root in thread-local storage (i.e. a traditional D global variable). That would thread through a number of free nodes available for allocation.

When a GC cycle occurs, it's okay if the list stays referenced; the GC will consider it "used" and won't do anything in particular about it. However, the GC cycle is a good opportunity to clean these freelists and offer the memory for other size classes, seeing as the freelists may grow unreasonably large and then just hold memory for no good reason.

A hook that nulls all freelist heads just as the collection process starts would be helpful.


Andrei

Reply via email to