Why Virtual Memory Address is the same in different process?

一曲冷凌霜 提交于 2019-12-17 21:28:18

问题


I know the virtual memory separates 2G(for kernel)/2G(for user) in Windows. But why the address of variable isn't stack continually?

Likes 0x22ff74,0x22ff78,0x22ff82,0x22ff86 ? Does it mean that Windows use sandbox mechanism in user process?


回答1:


That's exactly what virtual memory is. The operating system provides each program with its own private address space. In reality the operating system is in charge of mapping those virtual addresses back to the physical address space without the application being aware.

As you noticed this means that two applications can have different data residing at the same virtual address in the program.

Read more about virtual memory here.




回答2:


Are you confusing physical addresses and virtual addresses? It's ok for two processes to access the same virtual address, because each process see its own virtual memory space. On the other hand, all processes share the same physical memory space in the machine, so each process will have that same virtual address mapped to a different physical address (assuming there is no shared memory).




回答3:


Let me explicate it another way. Process X is running on machine A, and the same program is running as process Y on machine B. Does it matter if some global variable of your program takes same memory address on both machines? They are different! The same way, if that global variable is stored at XYZ location for one instance of process, another instance of process may have the same virtual address (XYZ) for that global variable.



来源:https://stackoverflow.com/questions/9208421/why-virtual-memory-address-is-the-same-in-different-process

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