编程环境中的虚拟地址空间 [英] Virtual address space in the context of programming

查看:122
本文介绍了编程环境中的虚拟地址空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对虚拟地址空间的含义感到困惑.在32位计算机中,进程可以寻址2 ^ 32个存储位置.这是否意味着每个进程的虚拟地址空间都是2 ^ 32(4GB)?

I am confused over what is meant by virtual address space. In a 32 bit machine a process can address 2^32 memory locations. Does that mean the virtual address space of every process is 2^32 (4GB) ?

以下是进程的虚拟地址空间的快照.可以增加到4GB吗?这样的系统中的进程数是否有限制?

The following is a snapshot of the virtual address space of a process. Can this grow upto 4GB? Is there any limit on the number of processes in such a system?

推荐答案

这可以增长到4GB吗?

地址空间的大小由唯一指针值的数量限制.对于32位处理器,32位值可以表示2 ^ 32个不同的值.如果允许每个这样的值寻址不同的内存字节,则将获得2 ^ 32字节,等于4 GB.

The size of the address space is capped by the number of unique pointer values. For a 32-bit processor, a 32-bit value can represent 2 ^ 32 distinct values. If you allow each such value to address a different byte of memory, you get 2 ^ 32 bytes, which equals four gigabytes.

因此,是的,一个进程的虚拟地址空间理论上可以增长到4 GB.但是实际上,这也可能取决于系统和处理器.可以看出:

So, yes, the virtual address space of a process can theoretically grow to 4 GB. However in reality, this may also depend on the system and processor. As can be seen:

但是,在奔腾类的处理器上无法达到此理论上的最大值.原因之一是段值的低位编码有关选择器类型的信息.结果,在65536个可能的选择器值中,只有8191个可用于访问用户模式数据.这会将您降至32TB.

This theoretical maximum cannot be achieved on the Pentium class of processors, however. One reason is that the lower bits of the segment value encode information about the type of selector. As a result, of the 65536 possible selector values, only 8191 of them are usable to access user-mode data. This drops you to 32TB.

请注意,有两种方法可以从系统分配内存,您当然可以使用C的malloc隐式为进程分配内存(您的问题被标记为

此处,具有2GB默认地址空间的32位Windows XP系统可以创建大约2025个线程:

According to some tests carried out here, A 32-bit Windows XP system with 2GB of default address space can create approximately 2025 threads:

但是,在分配了4GB地址空间的64位Windows XP上运行的32位测试限制 创建了接近3204个线程:

However a 32-bit test limit running on 64 bit Windows XP with 4GB allocated address space created close to 3204 threads:

但是,确切的线程和进程限制是极其可变的,它取决于许多因素.线程指定其堆栈大小的方式,进程指定其最小工作集的方式,可用的物理内存量以及系统提交限制.无论如何,在现代系统上,您通常不必担心这一点,因为如果您的应用程序确实超出了线程限制,则您应该重新考虑您的设计,因为几乎总是有其他方法可以完成此任务.数量合理的相同目标.

However the exact thread and process limit is extremely variable, it depends on a lot of factors. The way the threads specify their stack size, the way processes specify their minimum working set, the amount of physical memory available and the system commit limit. In any case, you don't usually have to worry about this on modern systems, since if your application really exceeds the thread limit you should rethink your design, as there are almost always alternate ways to accomplish the same goals with a reasonable number.

这篇关于编程环境中的虚拟地址空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆