Location of stack and heap

97 views Asked by At

When searching for memory layout images, you often come across diagrams where the stack is placed above the heap. However, occasionally there are images where the heap is placed above the stack. I want to know the reasons why the positions of the heap and stack can vary within the memory layout, which consists of heap/stack/.data/.bss/.text

searching , thinking

1

There are 1 answers

0
Diram_T On

The way the diagrams display stacks and heaps depend on the memory addressing layout the diagram opts for. Diagrams that have addresses growing downwards will often have the stack at the bottom, since most systems implementation opt for a stack that grows towards lower addresses. On the other hand, a memory diagram that have addresses growing upwards will have the stack growing downwards, which makes sense given that now addresses decrease as you go down in the diagram.

That being said, it is important to note that most memory diagrams are not true representation of what the physical memory looks like (with the exception of embedded systems that do not use address virtualisation). Those diagrams show what the virtual memory of a particular process looks like, but the actual memory layout is far more complicated as it has to account for multiple processes and page caching.