是2 GB真的是我最大的?的是、最大、GB

2023-09-02 10:53:50 作者:心动预兆

进程地址空间 的告诉我,我的.NET应用程序的最多只能使用2  GB在Windows XP上。真的吗?

Process Address Space tells me my .NET application at most can only use 2 GB on Windows XP. Is that true?

但是,如果我有一个20 terrabyte硬盘驱动器的内容。它会无法使用一些驱动器空间?

But what if I had a 20 terrabyte hard drive. Will it not be able to use some of that drive space?

推荐答案

这是说,这必须与RAM的答案是极其错误的。重要的是要正确地理解磁盘空间,RAM和地址空间之间的关系是很重要的。

The answers that say that this has to do with RAM are deeply wrong. It is important to correctly understand the relationship between disk space, RAM and address space.

下面是它到底是如何工作的。

Here's how it really works.

在32位Windows中的每个进程都有一个4  GB的地址空间的

Each process on 32 bit Windows is given a 4 GB address space.

这4&NBSP中; GB的地址空间,2  GB保留供使用的操作系统和其它2  GB可供用户code的过程中使用,因为它认为合适的

Of that 4 GB address space, 2 GB is reserved for the use of the operating system and the other 2 GB is available for the user code in the process to use as it sees fit.

现在让我就这点非常清楚:地址空间是不是内存。一个进程可以有尽可能多的内存作为就是了。我再说一遍:一个进程可以有超过4 NBSP方式多; GB的内存分配。的限制是只有2  GB该存储器可以在任何时候被映射到用户模式地址空间的

Now let me be extremely clear on this point: address space is not memory. A process can have as much memory as it wants. I'll say it again: a process can have way more than 4 GB of memory allocated. The limit is that only 2 GB of that memory can be mapped into the user-mode address space at any time.

我没有提到RAM因为 RAM无关的地址空间问题。没关系操作系统是否是存储过程的内存的在RAM或磁盘上或什么的。 RAM仅仅是一个性能优化,可以让操作系统存储在一个快速的芯片,而不是缓慢的磁盘的内存的。

I haven't mentioned RAM because RAM is irrelevant to the question of address space. It doesn't matter whether the operating system is storing the memory of the process in RAM or on disk or whatever. RAM is just a performance optimization that lets the operating system store the memory in a fast chip rather than a slow disk.

您历程告诉操作系统它有多少内存希望,以及在哪里内存映射到2  GB的地址空间。如果过程需要的时间超过2  GB内存那么这​​将是无法给它的所有映射到地址空间;这样一个过程或者需要被巧妙地写信告诉操作系统哪些内存页面映射和地址空间取消映射,或使用更少的内存。如果没有的话,将与外内存的异常而失败。

Your process tells the operating system how much memory it wants, and where to map that memory into the 2 GB address space. If the process needs more than 2 GB of memory then it will be unable to map it all into address space; such a process either needs to be cleverly written to tell the operating system which pages of memory to map and unmap from address space, or use less memory. If it does not then it will fail with an out-of-memory exception.

也许一个类比会有所帮助。您的大楼有一个停车场与百位。这是RAM。你有一个停车场沿着街道在这10000位。这是磁盘。你和其他人在每个建筑与空间上十个数字键钥匙圈。这是每个进程的地址空间。 就因为你只有房间十个键意味着你可以将自己只有十车?否!只要你想,你可以根据自己尽可能多的汽车,但如果你想访问这些车一一,你将不得不脱下钥匙圈的关键之一,它保存在别处,并把新的密钥在钥匙圈。 这是映射内存流入和流出的地址空间

Perhaps an analogy would help. Your building has a parking lot with a hundred spaces. That's RAM. You have a parking garage down the street with ten thousand spaces in it. That's disk. You and everyone else in the building each has a keyring with room for ten keys on it. That's per-process address space. Does the fact that you only have room for ten keys mean that you can own only ten cars? No! You can own as many cars as you want, but if you want to access eleven of those cars, you're going to have to take one of the keys off the keyring, store it somewhere else, and put the new key on the keyring. That's mapping memory into and out of address space.

如果大家在建筑的每个尝试停放车十的内存?如果停车场已满那么他们就必须换一些这些汽车的车库在街上停车。 这是否从对他们的钥匙扣钥匙阻止他们?否,显然不是。它只是使当他们想推动的是停在磁盘上车慢慢来。

What if everyone in the building each tries to park ten cars in RAM? If the parking lot gets full then they'll have to swap some of those cars to the parking garage down the street. Does that stop them from having keys on their keyrings? No, obviously not. It just makes it slow when they want to drive a car that is parked out on disk.

如果有什么是想通了这车的人更容易使用,以及较少使用的那些车库在街上停车感动代客停车服务? 这是内存管理器将不太最近使用的内存页到交换文件。

What if there was a valet service that figured out which cars people were more likely to use, and moved the less-used ones to the parking garage down the street? That's the memory manager putting less-recently-used memory pages into the swap file.

您指出的是,你有一个大的磁盘。假设你有一个10 NBSP; GB磁盘上的文件。你当然可以使用该文件的内容在您的.NET程序,但你不能把它统统装进去的连续的地址空间的一次。你必须阅读它的块。如果你是聪明的,你可以的它映射到进程的内存的一次全部 - 你有很多的内存的 - 但你不能再图10 NBSP;国标的内存的成2 NBSP; GB的的地址空间的

You point out that you have a big disk. Suppose you have a 10 GB file on that disk. You can certainly use the contents of that file in your .NET program, but you can't have it all loaded into contiguous address space at once. You have to read it in chunks. If you were clever you could map it into process memory all at once -- you've got plenty of memory -- but you couldn't then map 10 GB of memory into 2 GB of address space.

在一般更容易不是试图让那么多的记忆摆在首位;刚读它在几百KB的时间。

In general it is easier to not try to get that much memory in the first place; just read it in a few hundred KB at a time.

这是极为常见的人混淆的物理内存地址空间,但他们没有得到同样的事情了几十年。欲了解更多详细信息,请参阅在这个问题上我的文章的 Out内存不足并不是指物理内存 的。

It is extremely common for people to confuse address space with physical memory, but they have not been the same thing for decades. For more details, see my article on this subject, "Out Of Memory" Does Not Refer to Physical Memory.