It depends on the platform. On many platforms, this actually cannot be at all (the heap and stack are allocated on different pages and will not occur twice.
Keep in mind that the idea of ββgrowing a heap up and a stack growing down is only conceptual. On very small systems (for example, on old 8-bit microshes that ran CP / M), as well as on some POS and other systems with flat memory (without MMU or any other virtual or protected memory), the heap and stack could actually be that way. In this case, the behavior will be undefined ... but it will almost certainly fail as soon as the code tries to return to some address at the top of the damaged stack or follows an indirect pointer from one part of the heap to another or ...
In any case, you will not see it on any modern general-purpose workstation or on the server. You press the resource limit and get malfunctions in malloc, or you run into virtual memory, and ultimately the system will break into a trembling heap of βclick on the red switchβ.
Jim Dennis Aug 26 '09 at 11:36 2009-08-26 11:36
source share