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

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Jan 3 04:37:22 PST 2008


Lars Ivar Igesund wrote:
> 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.

Small correction: It's not all in a delegate. It's all in a function 
(that happens to return a delegate).
Not that it matters here...


More information about the Digitalmars-d-bugs mailing list