Linkers, Loaders & Executables
What is the advantage of laying out the heap and stack so they grow in opposite directions with a large gap between them?
- AThe gap can be shared flexibly even when it is unknown in advance how much each will use
- BBoth can use the same addresses at once, doubling memory
- CThe stack can never overflow
Show answer and explanation
Answer: A. The gap can be shared flexibly even when it is unknown in advance how much each will use
Because the heap grows up and the stack grows down, the gap between them serves a program that uses lots of heap as well as one that uses lots of stack. Giving each a fixed size could let one overflow while the other has room to spare. The stack usually has a set limit, though, and recursion that is too deep exceeds it and causes a stack overflow.
- A. Correct. It makes good use of the virtual address space.
- B. They cannot use the same addresses at once.
- C. Deep recursion and the like can still overflow the stack.