On 10.09.2011 0:55, Timon Gehr wrote:
On 09/09/2011 10:30 PM, Timon Gehr wrote:
void main(){
mixin({
string r;
foreach(i;0..12000) r~=q{mixin(q{{enum x="";}});};
return r;
}());
}

When I compile this program, DMD sometimes uses about 1GB of memory,
sometimes about 2GB of memory and sometimes it makes my OS crash.

Can anyone reproduce this?

Similarly this:

template TT(string s){enum TT=s;}

void main(){
mixin({
string r;
foreach(i;0..12000) r~=q{{enum x=TT!"";};};
return r;
}());
}

That does use a somewhat smaller amount of memory, but it is still huge
and non-deterministic in size.

I guess issue 6498, i.e. it's CTFE doing memory allocation on each append in foreach loop.
http://d.puremagic.com/issues/show_bug.cgi?id=6498

As for as non-determinism, maybe heap fragmentation?

--
Dmitry Olshansky

Reply via email to