64位内存不足异常 [英] Out of memory exception on 64bit
问题描述
im正在尝试创建以下数组
im trying to create the following array
int numOfArrays = 50000;
int lengthOfArrays = 13500;
long[,] unsortedNumbers = new long[numOfArrays,lengthOfArrays];
但是我不断遇到内存异常.我的目标是x64,我相信我已经设置了可识别大地址的标志,请参见图片,但我仍然遇到错误.奇怪的是,我在同一程序中有一个列表,它消耗了16gig的ram,没有任何问题.
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.
系统:
64gig ram
64gig ram
高清免费提供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位OS平台上运行
- 您正在使用NET 4.5,并且平台目标显示"AnyCPU" 并且您已取消选择"/取消选中首选32位",并且您正在64位OS平台上运行
- your Platform Target says "x64"
- you are using NET 4 and your Platform Target says "AnyCPU" and you are running on a 64bit OS platform
- you are using NET 4.5 and your Platform Target says "AnyCPU" and you have "prefer 32-bit" off/unticked and you are running on a 64bit OS platform
您正在分配:
50000 * 13500 * 8 = 5400000000字节= 5.029千兆字节
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屋!