-nogc

Georg Wrede georg.wrede at iki.fi
Thu Apr 23 08:30:22 PDT 2009


Andrei Alexandrescu wrote:
> 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.

No printable comment on that one...

> 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:

Today really seems to be the lucky day of D!
So many pieces are clicking together!!
Oh, my!

> 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. 

Of course.

> 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???)

I wish you'd elaborate.

> A disadvantage is that -nogc must be global - you can't link a program
> that's partially built with gc and partially without. This was a major
> counter-argument to adding optional gc to C++.

Well, IMHO, that's life. Can't win them all, all of the time. So let's 
live with it.

One might of course try to figure out a way to have the linker recognize 
this, or even *simpler*, the runtime might barf on it!!



More information about the Digitalmars-d mailing list