-nogc

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Apr 23 06:41:11 PDT 2009


Jason House wrote:
> Andrei Alexandrescu Wrote:
> 
>> I've discussed something with Walter today and thought I'd share it here.
>>
>> 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.
>>
>> So I'm thinking there should be a flag -nogc that enables a different
>> model of memory allocation. Here's the steps we need to take:
>>
>> 1. Put array definitions in object.d. Have the compiler rewrite "T[]" ->
>> ".Array!(T)" and "[ a, b, c ]" -> ".Array!(typeof(a))(a, b, c)". I think
>> superdan suggested that when he wasn't busy cursing :o).
> 
> I like that translation since it can allow customization. How will the type system handle Array!(const(T)) and const(Array!T)? They're no longer implicitly convertible.

We will need to accommodate multiple implicit conversions somehow anyway 
(e.g. multiple alias this entries). This is a great question because it 
illustrates how segregating arrays out of the language challenges the 
magic that made them "special" and democratizes good features such that 
other types can benefit of them too.

>> 2. Do the similar thing for associative arrays.
>>
>> 3. Have two object.d at hand: one is "normal" and uses garbage
>> collection, the other (call it object_nogc.d) has an entirely different
>> definition for arrays, hashes, and Object.
> 
> A version statement seems more powerful. Standard libraries may need changes too.
>  
>> 4. The definition of Object in object_nogc.d includes a reference count
>> member for intrusive refcounting.
> 
> That's still a method of garbage collecting! -nogc is kind of misleading...

Yah, I agree.

>> 5. Define a Ref!(T) struct in object_nogc.d that does intrusive
>> reference counting against T using ctors and dtor.
>>
>> 6. At this point we already have a usable, credible no-gc offering: just
>> use object_nogc.d instead of object.d and instead of "new Widget(args)"
>> use "Ref!(Widget)(args)".
> 
> Ick... Please make this hijack the default new behavior.

Agreed.


Andrei



More information about the Digitalmars-d mailing list