Re: Avoid GC with closures

2016-05-30 Thread Iakh via Digitalmars-d
On Sunday, 29 May 2016 at 11:16:57 UTC, Dicebot wrote: On 05/28/2016 09:58 PM, Iakh wrote: Yeah. It doesn't capture any context. But once it does it would be an error. Custom allocators are not very suitable for things like closures because of undefined lifetime. Even if it was allowed to

Re: Avoid GC with closures

2016-05-29 Thread ZombineDev via Digitalmars-d
On Sunday, 29 May 2016 at 11:16:57 UTC, Dicebot wrote: On 05/28/2016 09:58 PM, Iakh wrote: Yeah. It doesn't capture any context. But once it does it would be an error. Custom allocators are not very suitable for things like closures because of undefined lifetime. Even if it was allowed to

Re: Avoid GC with closures

2016-05-29 Thread Dicebot via Digitalmars-d
On 05/28/2016 09:58 PM, Iakh wrote: > Yeah. It doesn't capture any context. But once it does it > would be an error. Custom allocators are not very suitable for things like closures because of undefined lifetime. Even if it was allowed to replace allocator, you would be limited to either GC or RC

Re: Avoid GC with closures

2016-05-28 Thread Iakh via Digitalmars-d
On Thursday, 26 May 2016 at 21:10:30 UTC, bpr wrote: On Thursday, 26 May 2016 at 18:53:35 UTC, Iakh wrote: Functions with lambdas cannot be @nogc as far as they allocates closures. Counterexample: // Note that this is NOT a good way to do numerical quadrature! double integrate(scope double

Re: Avoid GC with closures

2016-05-28 Thread Iakh via Digitalmars-d
On Friday, 27 May 2016 at 10:34:38 UTC, Kagamin wrote: On Thursday, 26 May 2016 at 18:53:35 UTC, Iakh wrote: void g() @nogc { catch scope(void); int[N] arr = [/*...*/]; arr[].sort!((a, b) => a > b); } This compiles just fine and doesn't allocate: void g() @nogc { int[2] arr =

Re: Avoid GC with closures

2016-05-27 Thread Kagamin via Digitalmars-d
On Thursday, 26 May 2016 at 18:53:35 UTC, Iakh wrote: void g() @nogc { catch scope(void); int[N] arr = [/*...*/]; arr[].sort!((a, b) => a > b); } This compiles just fine and doesn't allocate: void g() @nogc { int[2] arr = [5,4]; arr[].sort!((a, b) => a > b); }

Re: Avoid GC with closures

2016-05-26 Thread bpr via Digitalmars-d
On Thursday, 26 May 2016 at 18:53:35 UTC, Iakh wrote: Functions with lambdas cannot be @nogc as far as they allocates closures. Counterexample: // Note that this is NOT a good way to do numerical quadrature! double integrate(scope double delegate(double x) @nogc f, double

Avoid GC with closures

2016-05-26 Thread Iakh via Digitalmars-d
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