数组中的最大元素数与最大索引器值 [英] Maximum number of elements in an array vs. maximum indexer value

查看:172
本文介绍了数组中的最大元素数与最大索引器值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我开始怀疑MSDN中的某些内容.本文演示了如何通过以下方式增加可分配的内存.NET 4.5和x64下的数组.这是一个不错的功能,但是Microsoft提供的描述中的某些内容使我感到困惑.

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.

在备注"部分中,他们说:

Under the section "Remarks" they say, that:

对于字节数组和单字节结构数组,任何单个维度的最大索引为2,147,483,591(0x7FFFFFC7),对于其他类型,最大索引为2,146,435,071(0X7FEFFFFF).

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.

因为我主要有 int [] double [] ,所以后一个数字与我的 indexing 有关.我可以使用 int [] TestArray = new int [2146435071] 创建一个数组,这很好.但是,在同一部分,Microsoft声明:

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:

数组中元素的最大数量为UInt32.MaxValue.

The maximum number of elements in an array is UInt32.MaxValue.

根据MSDN,哪个是:

Which is (according to the MSDN):

此常数的值为4,294,967,295;即十六进制的0xFFFFFFFF.

The value of this constant is 4,294,967,295; that is, hexadecimal 0xFFFFFFFF.

现在.如果我做对了,我可以有一个最多包含4,294,967,295个元素的数组(例如 ints ),但是由于该数组是由一个 int 而不是一个进行索引的> uint 我无法访问数据的上半部分"?

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?

这使我非常困惑,因为看来我在这里缺少了一些必不可少的东西.

This confuses me a lot, sice it seems I am missing something essential here.

我希望你能启发我

亲切的问候

我知道我可以创建多维数组,但是长度为2e9且宽度为2的数组似乎有点愚蠢.多维数组不是映射到一维数组吗?

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?

推荐答案

任何单个维度的最大索引 为2,147,483,591

The maximum index in any single dimension is 2,147,483,591

请记住,数组可以具有多个维度,因此您可以可以拥有一个二维数组,该数组最多可以包含4,294,967,295个项目,但是每个维度的最大长度可以为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.

因此您可以拥有2,147,483,591 X 2数组,但不能拥有1,000,000 X 1,000,000数组.

So you can have a 2,147,483,591 X 2 array, but not a 1,000,000 X 1,000,000 array.

这篇关于数组中的最大元素数与最大索引器值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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