memory layout of stack and heap in user space

时光怂恿深爱的人放手 提交于 2019-12-21 23:00:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!