Thread overview | |||||
---|---|---|---|---|---|
|
January 03, 2008 what is full closures | ||||
---|---|---|---|---|
| ||||
Sounds like something useful but what is full closure and what is the difference from the current (D1 - empty? :) ) closures? |
January 03, 2008 Re: what is full closures | ||||
---|---|---|---|---|
| ||||
Posted in reply to bobef | bobef wrote:
> Sounds like something useful but what is full closure and what is the difference from the current (D1 - empty? :) ) closures?
A full closure is where all data relevant to a delegate is retained until the delegate is destroyed. ie.
void delegate() fn( int i )
{
return delegate void() { writefln( "i is ", i ); };
}
fn( 1 )();
In D 1.0, this code would crash because the stack location for i no longer exists when the delegate is called. In D 2.0, memory for i is allocated on the heap and this code works.
Sean
|
January 03, 2008 Re: what is full closures | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | Oh, this is nice. Thank you for the explanation. |
Copyright © 1999-2021 by the D Language Foundation