大数组和OutOfMemory ERRor [英] large array and OutOfMemory ERRor
本文介绍了大数组和OutOfMemory ERRor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
i想要:
char [,,] array3d = new char [1000,1000,1000];
但是:
抛出了'System.OutOfMemoryException'类型的异常。
我可以使用硬替换RAM吗?
对不起我的英语很差
请帮帮我..
谢谢...
解决方案
.NET中没有单个对象可以超过2GB :这是绝对限制。并且数组是单个对象。
现在,1000个元素的3D数组似乎不会超过2GB - 它只有1,000,000,000个字符,不是吗?
但是......char
是16位(因为它是unicode)所以在直接字符中只有2,000,000,000字节,加上3D的开销数组可能会获得支持各种维度。基本上,您可以使用byte
值来实现,但char
只需将其推到边缘。
你可以做一个锯齿状阵列:
char [] [] [] array3d = new char [ 1000 跨度>] [] [];
for ( int x = 0 ; x < 1000 ; x ++)
{
array3d [x ] = new char [ 1000 ] [ ]。
for ( int y = 0 ; y < 1000 ; y ++)
{
array3d [x ] [y] = new char [ 1000 ];
}
}
因为这不会创建一个巨大的对象。
但是会很慢!
hello
i want:
char[,,] array3d = new char[1000,1000,1000];
but:
Exception of type 'System.OutOfMemoryException' was thrown.
Do i can use of Hard replace RAM?
sorry My english language is poor
please help me..
thanks...
解决方案
No single object in .NET can exceed 2GB: that is an absolute limit. And an array is a single object.
Now, it might not seem that a 3D array of 1000 elements would exceed 2GB - it's only 1,000,000,000 characters, isn't it?
But...char
is 16 bits (because it's unicode) so that's 2,000,000,000 bytes just in the direct chars, plus the overhead that a 3D array is likely to acquire to support the various dimensions. Basically, you could do it withbyte
values, butchar
just pushes it over the edge.
You could do it as a jagged array:
char[][][] array3d = new char[1000][][]; for (int x = 0; x < 1000; x++) { array3d[x] = new char[1000][]; for (int y = 0; y < 1000; y++) { array3d[x][y] = new char[1000]; } }
Because that doesn't create one single huge object.
Will be slow, though!
这篇关于大数组和OutOfMemory ERRor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文