A bug in my code

bearophile bearophileHUGS at lycos.com
Sun Sep 7 18:23:19 PDT 2008


Jarrett Billingsley:

>I think what you should be using instead is addRange.  addRoot more or less tells the GC "never collect memory referenced by this pointer", but it doesn't actually scan the memory _pointed to_ by the roots for pointers.  addRange tells the GC "scan this range of memory for pointers", which is what you want to tell the GC to do for Blocks. But then you run into another problem -- addRange and removeRange are terribly inefficient.<

Uhm... saddening.


>Uh, you don't have to do anything special.  You just use "new" to allocate a block of memory, and if it could contain pointers, and that block of memory is transitively accessible from the stack/registers/globals, then any pointers it contains will be scanned, and any memory pointed to by it will not be freed.<

That may be not enough to design a bit more complex data strutures, I don't know, we'll see.


>I think you're making things way more complicated than they need to be.<

For this toy program yes, but to create more complex data structures I'll need to learn more things about the GC.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list