什么是数组中元素的准确上限 [英] what is the exact maximum limit of elements in an array

查看:148
本文介绍了什么是数组中元素的准确上限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个purelly理论问题,所以请不要提醒我,在你的答案。

This is a purelly theoretical question, so please do not warn me of that in your answers.

如果我没有记错,而且由于在.NET每个阵列由索引的的Int32 ,从意味着指数范围 0 Int32.MaxValue

If I am not mistaken, and since every array in .NET is indexed by an Int32, meaning the index ranges from 0 to Int32.MaxValue.

假如没有记忆/ GC限制参与在.NET中的数组最多可以有 2147483648 (而不是 2147483647 )的元素。对吧?

Supposing no memory/GC constraints are involved an array in .NET can have up to 2147483648 (and not 2147483647) elements. Right?

推荐答案

那么,在的这是真的。事实上,在理论上有可能是更大的阵列支持 - 看到这个 Array.CreateInstance 签名这需要值的长度。使用C#索引器你就不能等指标数组,但你可以使用的 的GetValue(长)

Well, in theory that's true. In fact, in theory there could be support for larger arrays - see this Array.CreateInstance signature which takes long values for the lengths. You wouldn't be able to index such an array using the C# indexers, but you could use GetValue(long).

然而,在的实际的来讲,我不相信任何实现支持如此庞大的阵列。该CLR有每个对象的限制有点短2GB的,所以即使一个字节数组不能的真正的有2147483648元。实验有点表明,在我的盒子,你可以创造最大的数组是新的字节[2147483591] 。 (这是在64位.NET CLR。​​我已经安装了单声道的版本扼流圈上)

However, in practical terms, I don't believe any implementation supports such huge arrays. The CLR has a per-object limit a bit short of 2GB, so even a byte array can't actually have 2147483648 elements. A bit of experimentation shows that on my box, the largest array you can create is new byte[2147483591]. (That's on the 64 bit .NET CLR; the version of Mono I've got installed chokes on that.)

编辑:只是看着CLI的规范,它指定阵列具有下限和上限一个Int32的。这将意味着在 Int32.MaxValue 上限被禁止,即使他们可以与 Array.CreateInstance 调用。然而,它的的意味着它permissable到有界限的数组 Int32.MinValue ... Int.MaxValue ,即4294967296总共元素。

Just looking at the CLI spec, it specifies that arrays have a lower bound and upper bound of an Int32. That would mean upper bounds over Int32.MaxValue are prohibited even though they can be expressed with the Array.CreateInstance calls. However, it also means it's permissable to have an array with bounds Int32.MinValue...Int.MaxValue, i.e. 4294967296 elements in total.

编辑:再来看,ECMA 335分区第三节4.20( newarr )指定了一个初始化的矢量的类型与 newarr 有采取任何一个本地INT INT32 值。所以它看起来像,而正常的更宽松的阵列式的CLI术语必须具有 INT32 界限,一个载体类型没有。

Looking again, ECMA 335 partition III section 4.20 (newarr) specifies that a initializing a vector type with newarr has to take either a native int or int32 value. So it looks like while the normally-more-lenient "array" type in CLI terminology has to have int32 bounds, a "vector" type doesn't.

这篇关于什么是数组中元素的准确上限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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