Avoid GC with closures

Iakh via Digitalmars-d digitalmars-d at puremagic.com
Thu May 26 11:53:35 PDT 2016


Functions with lambdas cannot be @nogc as far as they allocates 
closures.
And the way lambdas works is completely different from C++ way. 
In D using
lambda we define how some part of "stack" frame allocates. So in 
some aspect
closure allocation is property of a function. So we need a way
to tell compiler how to handle this part of frame.
For exapmle:

void g() @nogc
{
     catch scope(void);
     int[N] arr = [/*...*/];
     arr[].sort!((a, b) => a > b);
}

Where "catch scope(void);" sets allocator for all lambdas. If it 
is void
closure will be allocated on the stack. Once we will have 
allocators we
will be able to pass them as closure handlers.


More information about the Digitalmars-d mailing list