[Issue 1760] New: Closures - Variable unnecessarily allocated on heap

Lars Ivar Igesund larsivar at igesund.net
Wed Jan 2 12:05:00 PST 2008


Frits van Bommel wrote:

> Lars Ivar Igesund wrote:
>> d-bugmail at puremagic.com wrote:
>> 
>>> is means that 'int b' is allocated on the heap, even though the function
>>> 'int getb()' is never referenced.
>> 
>> As Matti says, sort of a limitation, but not really one it is possible to
>> solve because the compiler can never know if an object referencing it is
>> linked in later on.
> 
> I disagree. In the example, no delegate pointing to three.getb() is ever
> created inside three(), and no other code can get to the symbol since it
> isn't in scope anywhere else. So the compiler could tell getb() doesn't
> even need to be emitted and 'b' can be stack-allocated, if only it would
> try to determine that fact.

Good point, didn't look to the top to see that it's all inside a delegate.

-- 
Lars Ivar Igesund



More information about the Digitalmars-d-bugs mailing list