进程地址空间与虚拟内存
根据我阅读几篇文章的理解,我假设进程地址空间(PAS)和虚拟内存(VM)是相同的。难道是我的理解有问题?有人可以解释一下这一点并启发我吗?我很困惑。
我知道进程地址空间与 RAM 或物理内存无关。
但只是对 PAS 和 VM 感到困惑。
From my understanding by reading several articles I assumed Process Address Space(PAS) and Virtual Memory(VM) are same. Is my understanding flawed? Can some one please shed some light on this and en light me? I am confused.
I understand Process Address Space has nothing to do with Ram or Physical memory.
But Just confused about PAS and VM.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一: “内存”不等于“地址空间”。地址空间是可能地址的范围。即 32 位指针为 4 Gb,64 位指针为 16 Eb。另一方面,内存是……嗯,你可以实际使用(至少可能)的内存。所以,我打赌您会问“进程内存”是否等于“虚拟内存”,或者“进程地址空间”是否等于“虚拟地址空间”。
第二:虚拟内存是唯一可以在用户模式下使用的内存。您无法访问物理内存。物理内存用于内核模式和驱动程序。用户模式应用程序仅使用虚拟内存工作。因此,所有内存在用户模式下都是虚拟的。无需附加“虚拟”。这是默认的。
因此,“进程地址空间”=“[虚拟]进程地址空间”——即单个进程的虚拟地址空间。 “内存”也是如此:“进程内存”=“[虚拟]进程内存”。
第三:现在,“虚拟内存”一词通常指的是“系统虚拟内存”(全局的东西),它比一个进程更大。另一方面:由于寻址是特定于进程的,因此不存在“系统虚拟地址空间”(所有进程和内核的全局地址空间)之类的东西。
所以,答案是:
示例
例如,进程地址空间的典型限制是 4 Gb(对于 32 位应用程序)。但是,进程虚拟内存的典型限制是 2 Gb(对于 32 位计算机可以扩展到 3 Gb,对于 64 位计算机可以扩展到 4 Gb)。
另一方面,虚拟内存比您的进程大。考虑通过 CreateFileMapping 函数分配内存时的情况。例如,您可以创建 64 GB 虚拟内存块。即使 64 Gb > 也没关系。 2 GB。当然,您不能同时使用所有 64 GB(因为进程地址空间只有 4 GB),但您可以分块使用,例如每 512 Mb。
另外,请考虑将同一虚拟内存块映射到多个位置(多个地址)时的情况。
换句话说,虚拟内存和虚拟地址之间不存在一对一的映射。
First: "memory" is not equal to "address space". Address space is range of posible addresses. I.e. it's 4 Gb for 32-bit pointers and 16 Eb for 64-bit pointers. On the other hand, memory is... well, memory which you can actually use (at least possibly). So, I bet you're asking if "process memory" is equal to "virtual memory" or if "process address space" is equal to "virtual address space".
Second: Virtual memory is the only memory which you can use in user mode. You can't access physical memory. Physical memory is for kernel mode and drivers. User mode applications work only with virtual memory. Thus, all memory is virtual in user mode. No need to append "virtual". It's by default.
Therefore, "Process Address Space" = "[Virtual] Process Address Space" - i.e. the virtual address space of the single process. The same goes for "memory": "Process Memory" = "[Virtual] Process Memory".
Third: Now, the "Virtual Memory" term usually refer to "System Virtual Memory" (global thing), which is larger than just one process. On the other hand: since addressing is specific to the process there is no such thing as "System Virtual Address Space" (global address space of all processes and kernel).
So, the answer is:
Examples
For example, the typical limit for process address space is 4 Gb (for 32-bit apps). However, a typical limit of process virtual memory is 2 Gb (which can be expanded up to 3 Gb for 32-bit machines or 4 Gb for 64-bit machines).
On the other hand, the virtual memory is larger than just your process. Consider the case when you allocate memory through CreateFileMapping function. You can create, say, 64 Gb virtual memory block. That's OK even though 64 Gb > 2 Gb. Of course, you can't use all 64 Gb at the same time (because process address space is just 4 Gb), but you can do it in chunks, say, per 512 Mb.
Also, consider the case when you map the same virtual memory block to mupliple locations (multiple addresses).
In other words, one-to-one mapping between virtual memory and virtual address doesn't exist.