[D2] How to not full closure?

Frank Benoit keinfarbton at googlemail.com
Mon Jul 14 15:42:29 PDT 2008


Mike schrieb:
> On Mon, 14 Jul 2008 04:39:58 +0200, davidl <davidl at 126.com> wrote:
> 
>> it's better to introduce a new keyword, closure.
>>
>> there
>>
>> on heap:
>> closure t = {
>>    // my closure
>>    return 3;
>> }
>>
>> on stack:
>> delegate t = {
>>    retirm 3;
>> }
> 
> Wouldn't it suffice to overload the new keyword?
> 
> heap:
> 
> delegate t = new { return 3; }
> 
> stack:
> 
> delegate t = { return 3; }
> 
> That way it could work with delegate literals too:
> 
> int b = 3;
> foo(new { return b; });
> 
> -Mike
> 
> 

I think the problem here is, new says that it will force a heap 
allocation for its call. But the heap allocation shall not happen per 
delegate, it shall only happen once for the surrounding stack frame if 
it contains at least one heap allocated delegate.
hm, is it understandable what i mean by this ? :)



More information about the Digitalmars-d mailing list