Windows stack and heap address ranges

2020-03-08 06:31发布

Working with Linux until now where stack addresses are very high and heap addresses are pretty low (as seen by printing heap and stack addresses using a C program), I have a problem with the Win32 process memory layout. MWSDN is saying that that stack addresses are higher than heap addresses, but from what I saw in practice, stack addresses are lower than heap addresses. So I am confused. Someone please explain.

1条回答
叛逆
2楼-- · 2020-03-08 07:06

Hm, stack addresses are higher than heap addresses - this is simply not true. Both stack and heap can reside anywhere in the address space of the process on Windows.

If you start a lot of threads, make huge heap allocations and load hundreds of dlls, you will find that all these objects are evenly spread around the address space.

enter image description here

This picture shows the structure of virtual allocations in a typical 32-bit process on Windows. Green shows free areas, blue that something is allocated. Activity is mostly taking place in the beginning of the address space but in other address ranges it is present also.

查看更多
登录 后发表回答