-nogc
Leandro Lucarella
llucax at gmail.com
Thu Apr 23 09:05:16 PDT 2009
Andrei Alexandrescu, el 23 de abril a las 05:58 me escribiste:
> 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).
>
> 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.
>
> 4. The definition of Object in object_nogc.d includes a reference count
> member for intrusive refcounting.
>
> 5. Define a Ref!(T) struct in object_nogc.d that does intrusive
> reference counting against T using ctors and dtor.
Oh! So you mean -nomarksweep then, right? Rerence counting *is* a garbage
collection algorithm.
> 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)".
>
> 7. Add a -nogc option to the compiler. In that mode, the compiler
> replaces automatically "T" -> "Ref!(T)" and "new T(args)" ->
> "Ref!(T)(args)" for all classes T except inside
> object_nogc.d. The exception, as Walter pointed out, is to avoid
> infinite regression (how do you implement Ref if the reference you hold
> inside will also be wrapped in Ref???)
>
> 8. Well with this all a very solid offering of D without garbage
> collection would be available at a low cost!
Besides this not being "non gc D", seems like a good idea. If I know there
were any chance that RC had a chance to be accepted in the D, I would
included it in my thesis.
> One cool thing is that you can compile the same application with and
> without GC and test the differences easily. That's bound to show a
> number of interesting things!
Please, stop calling it "without GC", is really confusing =)
--
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
More information about the Digitalmars-d
mailing list