Re: Garbage collection and closures.

2017-06-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 19 June 2017 at 09:18:56 UTC, Dsby wrote: void uses(scope void delegate() dg); will it be not alloc memory? I test it , if use scope it will not alloc memony. Right, using `scope` at the point the delegate variable is defined means it will never allocate.

Re: Garbage collection and closures.

2017-06-19 Thread Dsby via Digitalmars-d-learn
On Monday, 19 June 2017 at 09:10:16 UTC, Dsby wrote: On Saturday, 17 June 2017 at 17:15:50 UTC, Adam D. Ruppe wrote: On Saturday, 17 June 2017 at 14:19:34 UTC, ANtlord wrote: [...] Where the variable is defined that is referenced in the closure. So: [...] if the uses parma is 'scope':

Re: Garbage collection and closures.

2017-06-19 Thread Dsby via Digitalmars-d-learn
On Saturday, 17 June 2017 at 17:15:50 UTC, Adam D. Ruppe wrote: On Saturday, 17 June 2017 at 14:19:34 UTC, ANtlord wrote: [...] Where the variable is defined that is referenced in the closure. So: [...] if the uses parma is 'scope': void uses(scope void delegate() dg); will it be not

Re: Garbage collection and closures.

2017-06-17 Thread ANtlord via Digitalmars-d-learn
On Saturday, 17 June 2017 at 17:15:50 UTC, Adam D. Ruppe wrote: On Saturday, 17 June 2017 at 14:19:34 UTC, ANtlord wrote: Excuse me, I can't get what does it mean "deepest-referenced". What the deep you mean? The deep of a closure or deep of the function where the variable is defined. Can you

Re: Garbage collection and closures.

2017-06-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 17 June 2017 at 14:19:34 UTC, ANtlord wrote: Excuse me, I can't get what does it mean "deepest-referenced". What the deep you mean? The deep of a closure or deep of the function where the variable is defined. Can you give an example code? Where the variable is defined that is

Re: Garbage collection and closures.

2017-06-17 Thread ANtlord via Digitalmars-d-learn
On Saturday, 17 June 2017 at 13:13:17 UTC, Adam D. Ruppe wrote: On Saturday, 17 June 2017 at 13:03:28 UTC, ANtlord wrote: Is GC called every iteration of this loop? No, it will once on scope entry; where the deepest-referenced variable that is actually captured is defined. The compiler

Re: Garbage collection and closures.

2017-06-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 17 June 2017 at 13:03:28 UTC, ANtlord wrote: Is GC called every iteration of this loop? No, it will once on scope entry; where the deepest-referenced variable that is actually captured is defined. The compiler allocates heap space instead of stack space for the locals, then

Garbage collection and closures.

2017-06-17 Thread ANtlord via Digitalmars-d-learn
Hello! I can't understand one thing related to closures and calling of GC. I have the following demo snippet, where a closure is passed to `receive` function in a loop. bool isDone = false; while(!isDone) receive((bool val){ isDone = val }); Is GC called every iteration of this loop?