OutOfMemoryException异常的大阵声明 [英] OutOfMemoryException on declaration of Large Array
问题描述
我要创建一个相当大的双阵列12000ish点¯x55000ish。不幸的是,我得到一个内存不足的异常。我曾经用Java开发并可能更改内存设置。这可能与C#或只是不可能?我使用VS 2008。
I have to create a fairly large double array 12000ish x 55000ish. Unfortunately, I get an out of memory exception. I used to develop in Java and could change the memory settings. Is this possible with C# or is it just impossible? I am using VS 2008.
推荐答案
每个双击
是8个字节,所以你要分配一个单一阵列刚刚超过5GB 。该CLR有大约2GB IIRC每个对象的限制,即使是64位CLR。换句话说,它不是可用的内存总量这就是问题所在(虽然很明显,你就会有问题,如果你的不的有足够的内存),但每个对象的大小。
Each double
is 8 bytes, so you're trying to allocate a single array with just over 5GB. The CLR has a per-object limit of around 2GB IIRC, even for a 64-bit CLR. In other words, it's not the total amount of memory available that's the problem (although obviously you'll have issues if you don't have enough memory), but the per-object size.
我建议你把它分解成更小的阵列,背后或许一些描述一个门面。我不相信有什么办法可以变通方法,限制单个阵列。
I suggest you split it into smaller arrays, perhaps behind a facade of some description. I don't believe there's any way to workaround that limit for a single array.
编辑:您的可能的去数组的数组 - 又名一个的交错数组的:
You could go for an array of arrays - aka a jagged array:
double[][] array = new double[12000][];
for (int i = 0; i < array.Length; i++)
{
array[i] = new double[55000];
}
请问这是可以接受的吗?
Would that be acceptable to you?
(不能使用矩形阵列(双击[,]
),因为这将有相同的每个对象的大小问题。)
(You can't use a rectangular array (double[,]
) as that would have the same per-object size problem.)
这篇关于OutOfMemoryException异常的大阵声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!