-nogc

bearophile bearophileHUGS at lycos.com
Thu Apr 23 04:08:43 PDT 2009


Andrei Alexandrescu:
> The possibility of using D without a garbage collector was always
> looming and has been used to placate naysayers ("you can call malloc if
> you want" etc.) but that opportunity has not been realized in a seamless
> manner. As soon as you concatenate arrays, add to a hash, or create an
> object, you will call into the GC.

One simple possible solution: -nogc is to write C-like programs, with no automatic reference counting. It doesn't include the GC in the final executable (making it much smaller) and in such programs AAs and array concatenation and closures are forbidden (compilation error if you try to use them). "New" allocates using the C heap, and you have to use "delete" manually for each of them.
This is simple. While adding a second memory management system, ref-counted, looks like an increase of complexity for both the compiler and the programmers.


>1. Put array definitions in object.d. Have the compiler rewrite "T[]" -> ".Array!(T)"<

That has to be done with care an in a transparent way, not adding the Array name in the namespace, so you can create an Array youself, etc.

Bye,
bearophile



More information about the Digitalmars-d mailing list