W dniu 2014-11-22 o 17:56, Ary Borenszweig pisze:
On 11/21/14, 12:36 AM, Jonathan Marler wrote:
Has the idea of function overloading via nogc been explored?

void func() @nogc
{
     // logic that does not use GC
}
void func()
{
     // logic that uses GC
}
void main(string[] args) // @nogc
{
     // if main is @nogc, then the @nogc version of func
     // will be called, otherwise, the GC version will be
     func();
}

This could be useful for the standard library to expose different
implementations based on whether or not the application is using the GC.

If you have a version that doesn't use the GC, what's the reason to
prefer one that uses it?

Some algorithms (that swap pointers very often) may run faster with GC, but GC can cause stalls in your real time code. Nogc at main() is about preventing those stalls, even if nogc function will run slower (f.i. because pointer swaping adds some overhead needed to manage ownership - think about RC pointers). But *if* you want to use GC, it's more desirable to use faster GC version.

Reply via email to