IDEA: invariant-related gc hints

BCS ao at pathlink.com
Thu Jul 24 15:35:05 PDT 2008


Reply to Russell,

> Say that you create a new variable on the heap.  You fill it up with
> data, then cast it to invariant because you know that the contents
> will never change again.
> 
> That object might become garbage, of course, but you know that nothing
> it points to can possibly become garbage until the root object (the
> one that you cast to invariant) becomes garbage.
> 
> It seems to me that this information would be useful to the GC.  Just
> brainstorming here...but certainly, we could say, "until object X is
> garbage collected, objects A,B,C,D should all get marked 'live' in
> every GC sweep."
> 
> Moreover, the GC knows that all accessible data is also invariant, at
> least until the root reference goes away, so none of those objects
> need to be re-swept during a mark-and-sweep pass.
> 
> This sort of knowledge might really improve performance on programs
> that had a large set of invariant data.
> 
> Other ideas?
> 

the easiest way to effect this might be to put all the allocations in the 
same memory section. If you know you wont drop anything, a sequential allocator 
(all memory allocations will be adjacent) might do the trick

OTOH if the root becomes garbage but the rets is not you get a rather large 
block of garbage hanging around.





More information about the Digitalmars-d mailing list