分配大内存块时出现OutOfMemoryException [英] OutOfMemoryException when allocation large memory blocks
本文介绍了分配大内存块时出现OutOfMemoryException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的软件开发人员,
在我的应用程序中,我必须分配大量内存,但是当我尝试分配大于512 MB的内存时,以下C#控制台程序会创建OutOfMemoryException.我不知道为什么.
我的系统:
英特尔Core2 Quad CPU 3GB
Windows XP 32位
Visual Studio 2008
可用内存2.3GB
有人可以帮忙吗?
问候克里斯蒂安
Dear Softwaredevelopers,
In my application I have to allocate a huge amount of memory but the following C# console programm creates an OutOfMemoryException when I try to allocate memory >512 MB. and I wonder why.
My System:
Intel Core2 Quad CPU 3GB
Windows XP 32-Bit
Visual Studio 2008
available free memory 2.3GB
Can anybody help?
Greetings Christian
using System;
using System.Collections.Generic;
using System.Text;
namespace MemoryAllocation
{
class Program
{
static void Main(string[] args)
{
int size = 2;
while (size > 0)
{
Byte[] b = new Byte[size];
for (int i = 0; i<size; ++i)
b[i] = 13;
size *= 2;
}
}
}
}
推荐答案
对我来说,while
循环似乎很可疑-因为size
如果您继续这样加倍,它将永远不会低于零!
Thatwhile
loop looks suspicious to me - It''ll just keep allocating more and more memory until you run out, sincesize
will never get below zero if you keep doubling it like that!
基于这些,您的内存不足- ^ ]和 ^ ].
Based on these, you are running out of memory - here[^] and here[^].
这篇关于分配大内存块时出现OutOfMemoryException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文