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

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

问题描述

今天我开始想知道 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[] 后一个数字与我的索引相关.我可以用 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天全站免登陆