[D-runtime] GC expectations from TLS?

Steve Schveighoffer schveiguy at yahoo.com
Fri Nov 12 12:25:03 PST 2010


I'm assuming given the nature of the GC scanning mechanism, that globals and TLS 
variables are scanned conservatively.  Is this true?  If so, is there a way to 
prevent that?

Here is the issue I am thinking of.  Currently, in the array appending code, a 
cache is used to store the 8 most recently appended-to arrays.  The issue with 
this is, that 8-element cache is holding those arrays at bay, because the GC 
will never collect them.  That means, if you append to a huge array, and then 
throw away the data because you are done with it, it stays as unusable memory.

This is encapsulated as bug http://d.puremagic.com/issues/show_bug.cgi?id=3929

What I would like to do is change the cache into weak pointers, which would be 
purged when the referred-to arrays are collected in a collection cycle.  Before 
I do that however, I need to make sure the GC doesn't scan that cache.  But here 
is the problem, the cache is allocated like so:

BlkInfo[8] cache

Which is great, because it doesn't need a heap allocation, but is bad because 
even if I change the type to all value-types, I think it still will be scanned.

I would like to avoid a heap allocation (which I know will work) on every thread 
creation, but it's looking to me like this is what's going to have to happen.  I 
probably can use malloc to avoid it being scanned.  Is there another way?

-Steve



      


More information about the D-runtime mailing list