分配1000多MB的内存在32位的.NET程序分配、存在、程序、MB

由网友(花落微凉梦清幽)分享简介:我很奇怪,为什么我不能够分配更多的1000 MB的内存在我的32位.NET过程。下面的小应用程序已经分配1000 MB后抛出一个OutOfMemoryException。为什么1000 MB,而不是说1.8 GB?是否有一个进程范围的设置,我可以改变吗?I am wondering why I'm not able...

我很奇怪,为什么我不能够分配更多的1000 MB的内存在我的32位.NET过程。下面的小应用程序已经分配1000 MB后抛出一个OutOfMemoryException。为什么1000 MB,而不是说1.8 GB?是否有一个进程范围的设置,我可以改变吗?

I am wondering why I'm not able to allocate more that 1,000 MB of memory in my 32-bit .NET process. The following mini application throws an OutOfMemoryException after having allocated 1,000 MB. Why 1,000 MB, and not say 1.8 GB? Is there a process-wide setting I could change?

static void Main(string[] args)
{
    ArrayList list = new ArrayList();
    int i = 0;
    while (true)
    {
        list.Add(new byte[1024 * 1024 * 10]); // 10 MB
        i += 10;
        Console.WriteLine(i);
    }
}

PS:垃圾收集不利于

PS: Garbage collecting does not help.

修改,以澄清什么,我想:我已经写了非常大量的数据,其中涉及写入数据库/磁盘之前,服务器应用程序。而不是创造的一切临时文件,我已经写了一个内存缓存,这使得整个事情的速度超快。但记忆是有限的,所以我试图找出什么限制是。而且不知道为什么我的小测试程序扔OutOfMemoryException异常后,正是1000 MB。

Edit, to clarify what I want: I have written a server application which deals with very large amounts of data before writing to database/disk. Instead of creating temporary files for everything, I have written an in-memory cache, which makes the whole thing super-fast. But memory is limited, and so I tried to find out what the limits are. And wondered why my small test program threw the OutOfMemoryException after exactly 1,000 MB.

推荐答案

Win32进程的虚拟地址空间限制为1.5GB(并非完全如此)。此外,在.NET框架是有限制的内存%一个.NET程序可以消耗。在Machine.config有一个属性的memoryLimit这是可用内存中的进程可以消耗的%一processModel元素。默认值是60%。

The virtual address space limit of a Win32 process is 1.5GB (not entirely true). Additionally in the .NET frameworks there is a limiter to the % of memory a .NET process can consume. The machine.config has a processModel element with an attribute memoryLimit which is the % of available memory a process can consume. The default value is 60%.

如果你正在运行的机器有2GB的内存,或者你没有启用在BOOT.INI / 3GB开关,那么你会得到〜每个进程的内存1.3GB。

If the machine you're running on has 2GB of memory or you haven't enabled the /3GB switch in your BOOT.INI then you're going to get ~1.3GB of memory per process.

我找不到的知识库文章,但如果我没有记错的.NET 1.x中不能处理超出了1.5GB(1.8GB?)你的设置限制不管。

I can't find the KB article but if I remember correctly .NET 1.x cannot address beyond the 1.5GB (1.8GB?) limit regardless of your settings.

http://blogs.msdn.com/tmarq/archive/2007/06/25/some-history-on-the-asp-net-cache-memory-limits.aspx http://social.msdn.microsoft.com/Forums/en-US/clr/thread/c50ea343-b41b-467d-a457-c5a735e4dfff http://www.guidanceshare.com/wiki/ASP.NET_1.1_Performance_Guidelines_-_Caching#Configure_the_Memory_Limit

阅读全文

相关推荐

最新文章