digitalmars.D.bugs - [Issue 1760] New: Closures - Variable unnecessarily allocated on heap
- d-bugmail puremagic.com (34/34) Jan 01 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1760
- d-bugmail puremagic.com (8/8) Jan 01 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1760
- Lars Ivar Igesund (6/8) Jan 01 2008 As Matti says, sort of a limitation, but not really one it is possible t...
- Frits van Bommel (6/14) Jan 02 2008 I disagree. In the example, no delegate pointing to three.getb() is ever...
- Lars Ivar Igesund (4/19) Jan 02 2008 Good point, didn't look to the top to see that it's all inside a delegat...
- Frits van Bommel (4/21) Jan 03 2008 Small correction: It's not all in a delegate. It's all in a function
http://d.puremagic.com/issues/show_bug.cgi?id=1760 Summary: Closures - Variable unnecessarily allocated on heap Product: D Version: 2.009 Platform: PC OS/Version: Windows Status: NEW Severity: trivial Priority: P3 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: xnknet gmail.com Using this sample code: int delegate() three(){ int a = 35; int b = 60; int c = 75; int geta(){ return a; } int getb(){ return b; } writeln(&a); writeln(&b); writeln(&c); return &geta; } void main(){ three(); } Prints: 892FF4 892FF8 12FF28 This means that 'int b' is allocated on the heap, even though the function 'int getb()' is never referenced. --
Jan 01 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1760 matti.niemenmaa+dbugzilla iki.fi changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|trivial |enhancement ------- Not a bug, but a limitation. --
Jan 01 2008
d-bugmail 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. -- Lars Ivar Igesund
Jan 01 2008
Lars Ivar Igesund wrote:d-bugmail puremagic.com wrote: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.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.
Jan 02 2008
Frits van Bommel wrote:Lars Ivar Igesund wrote:Good point, didn't look to the top to see that it's all inside a delegate. -- Lars Ivar Igesundd-bugmail puremagic.com wrote: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.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.
Jan 02 2008
Lars Ivar Igesund wrote:Frits van Bommel wrote: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...Lars Ivar Igesund wrote:Good point, didn't look to the top to see that it's all inside a delegate.d-bugmail puremagic.com wrote: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.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.
Jan 03 2008