64 位内存不足异常 [英] Out of memory exception on 64bit
问题描述
我正在尝试创建以下数组
im trying to create the following array
int numOfArrays = 50000;
int lengthOfArrays = 13500;
long[,] unsortedNumbers = new long[numOfArrays,lengthOfArrays];
但我一直在处理内存异常.我的目标是 x64,我相信我设置了大地址感知标志,见图,但我仍然收到错误.奇怪的是,我在同一个程序中有一个列表,它消耗了 16gig 的内存而没有任何问题.
but i keep getting the out an memory exception. Im targeting x64, i believe ive set the large-address-aware flag, see pic, yet im still getting the error. Odd thing is, i have a list in the same program which consumes 16gig of ram without any issues.
系统:
64g 内存
100gig 免费高清.
100gig free on hd.
推荐答案
.NET 运行时中 32 位和 64 位进程的对象大小都有 2Gig 限制.
There's a 2Gig Limit on the size of objects in the .NET runtime for both 32bit and 64bit processes.
但是在 NET 4.5 中,您可以使用 gcAllowVeryLargeObjects
增加在运行时在 64 位进程中运行的 NET 代码的限制.
But in NET 4.5 you can increase the limit of NET code which is running on the runtime in a 64bit process with gcAllowVeryLargeObjects
.
如果出现以下情况,您的 NET 代码将作为 64 位运行:
Your NET code will be running as 64bit if:
- 您的平台目标显示x64"
- 您正在使用 NET 4 并且您的平台目标显示AnyCPU"并且您正在 64 位操作系统平台上运行
- 您使用的是 NET 4.5,并且您的平台目标显示AnyCPU"并且您已关闭/取消选中首选 32 位",并且您正在 64 位操作系统平台上运行
您正在分配:
50000 * 13500 * 8 = 5400000000 字节 = 5.029 GB
50000 * 13500 * 8 = 5400000000 bytes = 5.029 gigabytes
如果您没有使用 NET 4.5 的奢侈,那么根据您的使用场景,您可以使用 BigArray
代替:
If you don't have the luxury of using NET 4.5 then depending on your usage scenario you may be able to use BigArray
instead:
这篇关于64 位内存不足异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!