问题描述
我认为 64 位进程的最大用户空间是 8TB,但我做了一个小测试,我能得到的最大值是 10-11GB.
I thought that the maximum user space for a 64bit process was 8TB, but I did a little test and the maximum I could get is 10-11GB.
注意:我在一个过程中不需要那么多内存,我只是出于好奇想了解为什么.
Note: I don't need that much memory in a process, I just want to understand why out of curiosity.
这是我的测试程序:
static void Main(string[] args)
{
List<byte[]> list = new List<byte[]>();
while (true)
{
Console.WriteLine("Press any key to allocate 1 more GB");
Console.ReadKey(true);
list.Add(new byte[1024 * 1024 * 1024]);
Console.WriteLine("Memory size:");
double memoryUsage = Process.GetCurrentProcess().PeakVirtualMemorySize64 / (double)(1024 * 1024 * 1024);
Console.WriteLine(memoryUsage.ToString("0.00") + " GB");
Console.WriteLine();
}
}
更新了测试程序,使其更具确定性.
Updated the test program to be more deterministic.
为了接受答案,我想知道如果 8TB 只是理论上的,那么实际最大分配内存是如何计算的.
To accept an answer I would like to know how the real maximum allocated memory is calculated if 8TB is only theoretical.
推荐答案
高达 8 TB,而不是 8 TB.您最多可以拥有 8 TB,但您需要匹配的 RAM/交换文件.
It's up to 8 TB, not 8 TB. You can potentially have up to 8 TB, but you need the matching RAM/swapfile.
这篇关于.Net 为什么我不能在 x64 进程中获得超过 11GB 的分配内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!