today I started wondering about something in the MSDN. This article demonstrates, how one can increase the memory allocatable by an array under .NET 4.5 and x64. This is a nice feature, but something in the description provided by Microsoft baffeles me.
今天我开始怀疑MSDN中的某些东西。本文演示了如何增加.NET 4.5和x64下的数组可分配的内存。这是一个很好的功能,但微软提供的描述中有些东西会阻止我。
Under the section "Remarks" they say, that:
在“备注”部分,他们说:
The maximum index in any single dimension is 2,147,483,591 (0x7FFFFFC7) for byte arrays and arrays of single-byte structures, and 2,146,435,071 (0X7FEFFFFF) for other types.
对于字节数组和单字节结构数组,任何单个维度的最大索引为2,147,483,591(0x7FFFFFC7),对于其他类型,最大索引为2,146,435,071(0X7FEFFFFF)。
Since I mainly have int[]
or double[]
the latter number is relevant for my indexing. I can create an array with int[] TestArray = new int[2146435071]
, which is fine. However, under the same section Microsoft states:
由于我主要有int []或double [],后一个数字与我的索引相关。我可以使用int [] TestArray = new int [2146435071]创建一个数组,这很好。但是,在同一部分,微软声明:
The maximum number of elements in an array is UInt32.MaxValue.
数组中的最大元素数是UInt32.MaxValue。
Which is (according to the MSDN):
哪个(根据MSDN):
The value of this constant is 4,294,967,295; that is, hexadecimal 0xFFFFFFFF.
这个常数的值是4,294,967,295;也就是十六进制0xFFFFFFFF。
Now. If I get that right, I can have an array with up to 4,294,967,295 elements (for example ints
) but due to the array being indexed by an int
and not an uint
I am not able to access the "upper" half of my data?
现在。如果我做对了,我可以有一个最多4,294,967,295个元素的数组(例如整数),但由于数组是由int而不是uint索引的,我无法访问数据的“上半部分”?
This confuses me a lot, sice it seems I am missing something essential here.
这让我很困惑,看起来我似乎缺少必要的东西。
I hope you can enlighten me
我希望你能开导我
Kind Regards
亲切的问候
EDIT:
编辑:
I understand that I can create multi-dimensional arrays, but an array of length 2e9 an width 2 seems a bit stupid. Aren't multi-dimensional arrays mapped to one-dimensional ones anyway?
我知道我可以创建多维数组,但是长度为2e9且宽度为2的数组似乎有点愚蠢。不管多维数组是否映射到一维数组?
1 个解决方案
#1
4
The maximum index in any single dimension is 2,147,483,591
任何单个维度的最大索引为2,147,483,591
Remember that arrays can have multiple dimensions, so you could have a 2-D array that has up to 4,294,967,295 items, but each dimension can have a max length of 2,147,483,591.
请记住,数组可以有多个维度,因此您可以拥有一个最多包含4,294,967,295个项目的二维数组,但每个维度的最大长度可以为2,147,483,591。
So you can have a 2,147,483,591 X 2 array, but not a 1,000,000 X 1,000,000 array.
因此,您可以拥有2,147,483,591 X 2阵列,但不能拥有1,000,000 X 1,000,000阵列。
#1
4
The maximum index in any single dimension is 2,147,483,591
任何单个维度的最大索引为2,147,483,591
Remember that arrays can have multiple dimensions, so you could have a 2-D array that has up to 4,294,967,295 items, but each dimension can have a max length of 2,147,483,591.
请记住,数组可以有多个维度,因此您可以拥有一个最多包含4,294,967,295个项目的二维数组,但每个维度的最大长度可以为2,147,483,591。
So you can have a 2,147,483,591 X 2 array, but not a 1,000,000 X 1,000,000 array.
因此,您可以拥有2,147,483,591 X 2阵列,但不能拥有1,000,000 X 1,000,000阵列。