问题描述
根据本网站这里,在数组的最大范围
可以是 2GB以上
在 64
环境和实际的元素它可以容纳为 UInt32.MaxValue
。
As per this website here,the MaxSize of an array
can be more than 2GB
in the x64
environments and the actual elements it can hold is UInt32.MaxValue
.
所以,我做了我的app.config这样的:
So,I've made my app.config like :
<configuration>
<runtime>
<gcAllowVeryLargeObjects enabled="true" />
</runtime>
</configuration>
和我的数组声明和初始化是:
and my array declaration and initialization is :
int idsCount = 999999999;
long[] ids = new long[idsCount];
这是比少得多的 UInt32.MaxValue
,而是出现OutofMemory异常被抛出。
我做什么错误?
我的Framework版本也是 4.5
which is much less than the UInt32.MaxValue
,but an OutofMemory Exception was thrown.
Am I doing any mistake?
My Framework version is also 4.5
推荐答案
基本的检查表此故障:
-
当心这是默认启用的,当你连接调试器中运行您的程序的Visual Studio宿主进程。它使用的不同的的config文件,yourapp.vshost.exe.config。通过禁用选项快速消除此类事故的,项目+属性,调试选项卡。
Watch out for the Visual Studio Hosting process that's enabled by default when you run your program with the debugger attached. It uses a different .config file, yourapp.vshost.exe.config. Quickly eliminate this kind of mishap by disabling the option, Project + Properties, Debug tab.
这个时候你的程序运行在64位模式,而不是默认的一个新的项目只能工作。项目+属性,生成选项卡,一定要有目标平台设置值为anycpu和preFER 32位模式复选框取消选中。
This can only work when your process runs in 64-bit mode, not the default for a new project. Project + Properties, Build tab, be sure to have the Platform target set to AnyCPU and the "Prefer 32-bit mode" checkbox unticked.
虽然你在那里,单击应用程序选项卡,然后仔细检查目标框架设置。必须是4.5,当然以上。
While you are there, click the Application tab and double-check the Target framework setting. Must be 4.5 or higher of course.
Windows版本的问题,不同的版本有不同的限制进程的最大虚拟内存大小。回顾这个MSDN网页并找到您的Windows版本和版本。你会遇到与Windows 7家庭普通版为例,8 GB的最大。
The Windows version matters, different versions have different limits for the maximum VM size of a process. Review this MSDN page and locate your Windows version and edition. You'd run into trouble with Windows 7 Home Basic for example, 8 Gigabytes max.
大的分配在64位模式下可以在提交失败失败的。承诺是技术术语在操作系统的页面文件保留空间。它作为后备存储的情况下,你的大阵需要被换出,以腾出空间给其他进程。 pretty的多一定会发生的,如果你的机器没有超过8 GB的可用RAM。你可能有大小限制设置过低或者操作系统无法生长分页文件速度不够快,给你你需要的空间。在这个博客帖子由Mark Russinovich的的。
Large allocations in 64-bit mode can fail on a commit failure. Committing is the technical term for reserving space in the operating system's paging file. It acts as the backing-store in case your large array needs to be paged-out to make room for other processes. Pretty much guaranteed to happen if your machine doesn't have well over 8 Gigabytes of RAM available. You might have the size limit set too low or the OS can't grow the paging file quick enough to give you the space you need. Demonstrated well in this blog post by Mark Russinovich.
这篇关于阵列的.Net框架4.5 MAXSIZE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!