A question/suggestion regarding the GC

bearophile bearophileHUGS at lycos.com
Sat Sep 20 12:04:26 PDT 2008


In \phobos\internal\gc\gc.d  there's this function:

void setTypeInfo(TypeInfo ti, void* p) {
  if (ti.flags() & 1)
    hasNoPointers(p);
  else
    hasPointers(p);
}

At first sight the code of that function looks wrong, because if you call it like this:

struct S { int* pi, int i }
setTypeInfo(typeid(S), void* p);

then the GC will look for pointers in the 'i' field too. So setTypeInfo() becomes nearly useless to me and I can use my HasReferences!() template and call hasNoPointers/hasPointers manually.

TypeInfo knows at runtime the name of the type, so at runtime it can use an associative array to find the name mangling of the given type, and with that it can determine if each field of S is a pointer/reference or not (and it can even store such information into a bitarray for future needs, so the name demangling is done only once, and only for types that receive a typeid() call on them). This isn't perfect because it may mark as reference pointers to not-GC-managed memory, but it look better than the current situation anyway.

I think this isn't going to slow down D code. And can make the GC a bit more precise. I think this may help speed up the deallocation/management of associative arrays too.

I am surely missing many details and I can be wrong, so if you want you can tell me what I am wrong about, so I can learn a bit more.

Bye and thank you,
bearophile


More information about the Digitalmars-d-learn mailing list