DConf 2013 Day 2 Talk 5: A Precise Garbage Collector for D by Rainer Schütze

bearophile bearophileHUGS at lycos.com
Mon Jul 1 03:30:15 PDT 2013


Rainer Schuetze:

> In the proposed implementation, the gc_emplace function can be 
> used to pass this information to the GC. This would need to be 
> called whenever the location of pointers changes, so it's not 
> high-performance.

Thank you for the answer.

Let me see if I understand what you are saying. If I have an 
usage of Algebraic like this, at line 4 x contains no GC-managed 
pointers, while at line 6 it contains a pointer to the array data:


import std.variant: Algebraic;
void main() {
     alias T = Algebraic!(ulong, int[]);
     T x = 1UL;  // line 4
     auto items = [1, 2];
     x = items; // line 6
     x = 2UL;   // line 7
     x = items; // line 8
}


You say that every time you change the _type_ of the contents of 
x you have to call gc_emplace.

But isn't the D GC called only when an allocation occurs? So 
what's the point of calling gc_emplace (at lines 7 and 8) if no 
garbage collection happens? Isn't it possible for the GC to use 
(and update) this information lazily, only when a collection 
occurs?

(Extra note: Algebraic is meant for functional-style programming. 
In such kind of programming data is mostly immutable. This means 
you don't change the contents and the type of an algebraic 
variable once it is assigned. So usually you call gc_emplace only 
once for one of such variables).

Bye,
bearophile


More information about the Digitalmars-d-announce mailing list