Stack Space & Ackermann
Era Scarecrow via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 4 22:03:24 PST 2017
On Thursday, 5 January 2017 at 04:53:23 UTC, rikki cattermole
wrote:
> Well, you could create a fiber[0].
>
> Fibers allow you to set the stack size at runtime.
>
> [0] http://dlang.org/phobos/core_thread.html#.Fiber.this
Well that certainly does seem to do the trick. Unfortunately I
didn't get the next output because I ran out of memory to
allocate/reallocate over 2Gb :P
I suppose with a 64bit compiling the program might run a bit
longer and succeed further (with 24Gigs of ram), however the
sheer amount of memory required will make this little exercise
more or less a waste of time.
Still that was an interesting way around the (stackframe)
problem, one I'll keep I mind (should i need it again).
void m() {
foreach(i; iota(6))
foreach(j; iota(6)) {
writefln("Ackerman (%d,%d) is : %d", i,j,ack(i,j));
}
}
int main(string[] args) {
Fiber composed = new Fiber(&m, 2<<28); //512MB
composed.call();
return 0;
}
results:
Ackerman (3,5) is : 253
Ackerman (4,0) is : 13
Ackerman (4,1) is : 65533
core.exception.OutOfMemoryError at src\core\exception.d(693): Memory
allocation failed
More information about the Digitalmars-d-learn
mailing list