问题
I'm recently studying the OS, and here is a picture online showing the memory layout of user space and kernel space, and the layout of stack, heap and so on.
In this figure I see that the stack is at the highest memory address in user space, higher than the heap, data segment and so on.
In order to check that, I used the memory watcher window in vs2012 under debug view, here's my code:
int a = 3;
int main()
{
int b = 5;
int *p = new int[100];
delete [] p;
return 0;
}
And I checked the memory address of a(data segment),b(stack variable) and p(heap), but I found the address of b is the lowest among the three, so why is the result different from the picture above?
回答1:
That image looks like how Linux lays out the virtual address space, not Microsoft Windows.
回答2:
I have a memory map for a program in win32 which may help, it outlines the mapping for systems not using the /3gb switch:
As you can see win32 uses a slightly different memory mapping than linux (as pointed out in the other question) which the diagram you posted looks like. I realise this memory diagram is old, however the same base tenets mostly apply in windows.
Let me know if you need more info though and I will try and rustle something up:)
来源:https://stackoverflow.com/questions/22801666/memory-layout-of-stack-and-heap-in-user-space