July 14, 2011 Lazy and delegates - out-of-scopeness - what happens? | ||||
---|---|---|---|---|
| ||||
If I pass lazy expressions or delegates to as arguments to functions, what happens with variables mentioned in the lazy expression or in the delegate body if those variables are on the stack or otherwise out of scope, or are objects that may be freed? Does the compiler partially protect the programmer from mistakes here? If anyone can comment on how these features are implemented in generated code wrt stack-allocated objects that are _in_ lexical scope in a delegate evaluation context, then I'd be interested to hear about this. |
July 14, 2011 Re: Lazy and delegates - out-of-scopeness - what happens? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cecil ward | On 2011-07-14 20:42, Cecil ward wrote: > If I pass lazy expressions or delegates to as arguments to functions, what happens with variables mentioned in the > lazy expression or in the delegate body if those variables are on the stack or otherwise out of scope, or are objects > that may be freed? Does the compiler partially protect the programmer from mistakes here? > > If anyone can comment on how these features are implemented in generated code wrt stack-allocated objects that > are _in_ lexical scope in a delegate evaluation context, then I'd be interested to hear about this. They all local variables (or similar) that a delegate references will be allocated on the heap, this is also known as a closure: http://en.wikipedia.org/wiki/Closure_%28computer_science%29 -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation