Why do we have stack overflows?

Adrian Hey ahey at iee.org
Fri May 4 10:28:58 EDT 2007


Malcolm Wallace wrote:
> Just FYI, nhc98 has a single memory area in which the stack and heap
> grow towards each other.  Memory exhaustion only happens when the stack
> and heap meet in the middle and GC fails to reclaim any space.
> 
> However, it can only do this because it is single-threaded.  As soon as
> you need a separate stack for each thread in a multi-threaded system,
> this nice one-dimensional model breaks down.

Yes. A while ago I did the same thing with a toy FPL I was tinkering
with. But like nhc98, it was single threaded.

But I don't believe this is a serious extra complication. ghc does
seem to have the capability to grow stacks effectively without
bound (and presumably shrink them too), but it doesn't do this by
default for reasons I don't understand.

My preference would be to have an upper limit on total (stack+heap)
memory used. Also, as Stefan has suggested, I think stack should
grow linearly, not exponentially. But I don't really know enough
about the innards of ghc rts to know what might or might not be
possible/easy/difficult.

Regards
--
Adrian Hey



More information about the Glasgow-haskell-users mailing list