简体   繁体   English

.Net Framework 4.5中的数组的MaxSize

[英]MaxSize of array in .Net Framework 4.5

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 . 按照这个网站在这里 ,该MaxSize of an array可以more than 2GBx64环境中,它可以保存实际元素是UInt32.MaxValue

So,I've made my app.config like : 所以,我已经使我的app.config像:

<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. 这比UInt32.MaxValue ,但抛出了OutofMemory Exception。
Am I doing any mistake? 我有什么不对吗?
My Framework version is also 4.5 我的框架版本也是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. 当您运行附带调试器的程序时,请注意默认启用的Visual Studio Hosting进程。 It uses a different .config file, yourapp.vshost.exe.config. 它使用不同的 .config文件yourapp.vshost.exe.config。 Quickly eliminate this kind of mishap by disabling the option, Project + Properties, Debug tab. 通过禁用选项Project + Properties,Debug选项卡快速消除此类事故。

  • This can only work when your process runs in 64-bit mode, not the default for a new project. 这仅在您的进程以64位模式运行时才有效,而不是新项目的默认模式。 Project + Properties, Build tab, be sure to have the Platform target set to AnyCPU and the "Prefer 32-bit mode" checkbox unticked. Project + Properties,Build选项卡,确保将Platform目标设置为AnyCPU,并取消选中“Prefer 32-bit mode”复选框。

  • While you are there, click the Application tab and double-check the Target framework setting. 当您在那里时,单击“应用程序”选项卡并仔细检查“目标”框架设置。 Must be 4.5 or higher of course. 当然必须是4.5或更高。

  • The Windows version matters, different versions have different limits for the maximum VM size of a process. Windows版本很重要,不同版本对进程的最大VM大小有不同的限制。 Review this MSDN page and locate your Windows version and edition. 查看此MSDN页面并找到您的Windows版本和版本。 You'd run into trouble with Windows 7 Home Basic for example, 8 Gigabytes max. 例如,Windows 7 Home Basic遇到了麻烦,最多8 GB。

  • Large allocations in 64-bit mode can fail on a commit failure . 64位模式下的大量分配可能会在提交失败时失败 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. 如果你的机器没有超过8千兆字节的RAM可用,那么几乎可以肯定会发生。 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. Mark Russinovich在这篇博客文章中证明了这一点

AC# long is 64 bits, or 8 bytes. AC# long是64位,或8字节。 The array ids is dimensioned for one less than one billion entries, at 8 bytes per entry. 数组ids的大小为一个不到十亿个条目,每个条目8个字节。 That array as defined will use around 8GB. 定义的数组将使用大约8GB。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM