How delegate context work?

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 16 08:21:44 PDT 2017


On Thursday, 16 March 2017 at 14:53:27 UTC, Eko Wahyudin wrote:
> How D access xxx variable? where context pointer refer to?
> How D keep xxx variable persistent?
> Why xxx is not swapped out when we leave first delegate?

The compiler sees that you are going to reference the variable, 
and copies it to a heap buffer on function entry, so it uses that 
instead of the stack.

That heap buffer is reused across the delegates which is why it 
doesn't swap out (this is the same as Javascript's vars, but 
different than JS's `let` and C# and other languages).



More information about the Digitalmars-d-learn mailing list