Why Virtual Memory Address is the same in different process?

后端 未结 3 592
广开言路
广开言路 2020-12-11 07:55

\"http://i.stack.imgur.com/RGMsz.png\"

I know the virtual memory separates 2G(for kernel)/2G(for user) in Windo

相关标签:
3条回答
  • 2020-12-11 08:21

    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.

    0 讨论(0)
  • 2020-12-11 08:26

    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).

    0 讨论(0)
  • 2020-12-11 08:31

    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.

    0 讨论(0)
提交回复
热议问题