Regarding the more precise GC

bearophile bearophileHUGS at lycos.com
Sat Apr 21 17:28:18 PDT 2012


In the main D newsgroup I have seen the two recent threads 
regarding a more precise GC in D. I have two questions about 
that, that seem more fit for D.learn.

1) I have not fully understood the performance and memory 
implications of the more precise GC. In the thread I think I've 
seen a memory overhead in every allocated struct. Is it possible 
to disable this bookkeeping/overhead for smaller programs that 
enjoy/need a GC but probably don't need a precise GC because they 
run only for no more than 30 seconds? Many of my small D programs 
are command-line utilities with a short run-time, but they often 
need a GC.


2) If I have a tagged union, like:


static bool isPointer;

union Foo {
     size_t count;
     int* ptr;
}

In every point of my program I know that inside a Foo there is a 
pointer or a size_t according to the value isPointer (a similar 
case is if I use a single bit tagging inside a size_t to denote 
if it's a pointer or an integral value. The D docs say that in 
the current conservative GC design such pointer tagging with a 
single bit is not allowed if the pointer is to CG-managed memory, 
but the union is allowed. Maybe with the more precise GC even the 
pointer tagging gets possible).

Is it possible to tell to the precise GC every time it performs a 
collection if a Foo contains a pointer to follow, or if it 
instead contains just an integral value to ignore? I think it 
needs to be a function pointer or some kind of callback.

Bye and thank you,
bearophile


More information about the Digitalmars-d-learn mailing list