It became necessary to study in detail how the memory is arranged in a computer. A colleague on the forum has recommended this article on Habré , which will give the minimum that a software developer needs.
In the section “Address Space”, the author demonstrates by example in C that the virtual memory segments actually go in order: “code-heap-stack”.
I also ran this code:
#include <stdio.h> #include <stdlib.h> int main() { int v = 3; printf("Code is at %p \n", (void *)main); printf("Heap is at %p \n", malloc(8)); printf("Stack is at %p \n", (void *)&v); _getch(); return 0; } and that's what happened to me:
Code is at 001B1299
Heap is at 00FF5168
Stack is at 00EFF87C
Using an online resource , I translated these addresses from hexadecimal to decimal and got:
Code is at 001B1299 => 1774233 (1)
Heap is at 00FF5168 => 16732520 (3)
Stack is at 00EFF87C => 15726716 (2)
If you rank these values, it turns out that the order (see the numbers in brackets) of the segments of the allocated virtual memory for the process is: “code- stack- heap”, and not as shown by the author in the illustration
“Code- pile- stack”
Question
Where am I wrong? What did not understand?
I can not continue to read the article until I understand this piece).
