Delegate Memory Usage & Optimization
Maxime Chevalier-Boisvert
maximechevalierb at gmail.com
Wed Dec 11 20:37:41 PST 2013
I went ahead and wrote a little test program:
---------
import std.stdio;
alias int delegate() Dg;
Dg[] dgList;
Dg foo()
{
auto f = delegate int()
{
return 0;
};
return f;
}
Dg bar()
{
int n = 0;
auto f = delegate int()
{
return n++;
};
return f;
}
void main()
{
auto d0 = foo();
writeln(d0.ptr);
dgList ~= d0;
auto d1 = bar();
writeln(d1.ptr);
dgList ~= d1;
}
---------
This outputs:
null
7F37305DDFF0
So it seems DMD optimizes this well, as I had hoped.
More information about the Digitalmars-d
mailing list