Franciszek Czekala <[email protected]> wrote:
I am not sure that this is a correct answer. 1600 bytes is just 100x2x8
bytes.
Since delegates are fat (double) pointers this is probably just the
memory
occupied by dlg variables themselves, not the memory to which they
point. Indeed
adding an extra z variable in my code to the g() function and using it
in writeln
does not change the output: it is still 1600 bytes.
Wrong. The delegates would be 100x2x4 bytes, as DMD only produces 32-bit
exes. The 16 bytes per delegate is because that's the smallest block the
GC will allocate.
Proof:
long recurse( long delegate() dg ) {
long n = 1;
long m = 0;
long r = 0;
long s = 0;
long t = 0;
return GC.sizeOf( dg.ptr ) + ( dg() ? recurse( { return dg() - n + m -
r + s + t; } ) : 0 );
}
void main(){
writeln( recurse( { return 100L; } ) );
}
Outputs 6400.
--
Simen