.Net Framework 4.5 中数组的 MaxSize [英] MaxSize of array in .Net Framework 4.5

查看:33
本文介绍了.Net Framework 4.5 中数组的 MaxSize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据本网站此处MaxSize在x64 环境中,数组 可以超过2GB,它可以容纳的实际元素是UInt32.MaxValue.

所以,我的 app.config 如下:

<预><代码><配置><运行时><gcAllowVeryLargeObjects enabled="true"/></运行时></配置>

我的数组声明和初始化是:

int idsCount = 999999999;long[] ids = new long[idsCount];

远小于 UInt32.MaxValue,但抛出 OutofMemory 异常.
我做错了吗?
我的框架版本也是4.5

解决方案

此故障的基本检查清单:

  • 当您运行带有调试器的程序时,请注意默认启用的 Visual Studio 托管进程.它使用不同 .config 文件,yourapp.vshost.exe.config.通过禁用选项、项目 + 属性、调试选项卡来快速消除这种故障.

  • 这仅在您的进程以 64 位模式运行时才有效,而不是新项目的默认模式.项目 + 属性,构建选项卡,确保将平台目标设置为 AnyCPU 并取消选中首选 32 位模式"复选框.

  • 当您在那里时,单击应用程序选项卡并仔细检查目标框架设置.当然必须是 4.5 或更高.

  • Windows 版本很重要,不同版本对进程的最大 VM 大小有不同的限制.查看此 MSDN 页面并找到您的 Windows版本和版本.例如,您在使用 Windows 7 Home Basic 时会遇到问题,最多 8 GB.

  • 64 位模式下的大量分配可能会因提交失败而失败.提交是在操作系统的页面文件中保留空间的技术术语.它充当后备存储,以防您的大型阵列需要调出以便为其他进程腾出空间.如果您的机器没有超过 8 GB 的可用 RAM,几乎肯定会发生.您可能将大小限制设置得太低,或者操作系统无法足够快地扩展分页文件来为您提供所需的空间.在 Mark Russinovich 的这篇博文中得到了很好的证明.

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.

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];  

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

解决方案

The basic check-list for this failure:

  • 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.

  • 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.

  • While you are there, click the Application tab and double-check the Target framework setting. Must be 4.5 or higher of course.

  • 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.

  • 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 Framework 4.5 中数组的 MaxSize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆