什么是.NET阵列对64位Windows的最大长度 [英] What is the maximum length of an array in .NET on 64-bit Windows

查看:217
本文介绍了什么是.NET阵列对64位Windows的最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听到有人在.NET中最大的数组大小为4 GB?只是想知道如果这是真的。你做梦也不会想到在32位.NET这样做的,但在64位系统与12 GB的RAM,也许,只是也许你可能想做到这一点。 : - )

I heard from someone that the maximum array size in .NET is 4 GB? Just wondering if that is true. You wouldn't dream of doing this on 32-bit .NET but on a 64-bit system with 12 GB of RAM, maybe, just maybe you might want to do this. :-)

推荐答案

这是数组,理论上最多有2,147,483,647元,因为它使用了一个int索引。实际的限制比这个略低,这取决于包含在数组中的类型。

An array could theoretically have at most 2,147,483,647 elements, since it uses an int for indexing. The actual limit is slightly lower than this, depending on the type contained within the array.

然而,在.NET CLR 2GB的最大单一对象的限制,即使是在64位。这是设计完成。

However, there is a 2GB maximum single object restriction in the .NET CLR, even in 64bit. This was done by design.

您可以轻松地做出一个的IList< T> 实施的,在内部,保持多个阵列,并允许您增长超过2GB的单个对象的限制,但是没有一个在框架本身

You can easily make an IList<T> implementation that, internally, keeps multiple arrays, and allows you to grow beyond the 2GB single object limit, but there is not one in the framework itself.

典型地,然而,这不是一个实际问题。在大多数情况下,你必须阵列指着大班 - 这样的阵列只是抱着引用。这意味着你的阵列可以有效地指向内存很多很多绿带 - 但数组本身不能是> 2GB

Typically, however, this is not a real problem. Most of the time, you'll have arrays pointing to large classes - so the array is just holding references. This would mean your array can effectively point to many, many GBs of memory - but the array itself cannot be >2GB.

需要注意的是,由于.NET 4.5,有可用的新选项,其中的64位应用程序可以选择在:<一href="http://msdn.microsoft.com/en-us/library/hh285054%28v=vs.110%29.aspx">gcAllowVeryLargeObjects.有了这个新的选项设置,可以让 UInt32.MaxValue (4,294,967,295)在多维数组的元素,虽然是一维数组仍限于2146435071元素( 2147483591单字节数组或含有任何一个结构的阵列UT斯达康字节)。

Note that, as of .NET 4.5, there is a new option available where 64bit applications can opt-in: gcAllowVeryLargeObjects. With this new option set, it is possible to get UInt32.MaxValue (4,294,967,295) elements in a multi-dimensional array, though a single dimensional array is still limited to 2,146,435,071 elements (2,147,483,591 for single byte arrays or arrays of a struct containing nothing ut a byte).

此选项的新规则是:

  • 元素的数组的最大数量为UInt32.MaxValue。
  • 在任何一个维度的最大指数为2147483591(0x7FFFFFC7)字节数组和单字节结构数组,和2146435071(0X7FEFFFFF)其他类型。
  • 字符串和其他非数组对象的最大大小是不变的。

这篇关于什么是.NET阵列对64位Windows的最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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