简体   繁体   English

我可以在.NET 4.5下创建的最大数组是什么?

[英]What is the largest array I can create under .NET 4.5?

I'm experimenting with memory limits on my x64 machine (Windows7) under .NET 4.5. 我正在尝试在.NET 4.5下的x64计算机(Windows7)上使用内存限制。 Based on this documentation (as referred to in this answer ) it seems like I should be able to create an array with up to UInt32.MaxValue elements. 根据此文档 (如本答案中所述 ),似乎我应该能够创建一个最多UInt32.MaxValue元素的数组。 So I enabled gcAllowVeryLargeObjects and tried to create the following array: 因此,我启用了gcAllowVeryLargeObjects并尝试创建以下数组:

int[] arr = new int[UInt32.MaxValue]; //2^32

However, this generates an OverflowException: ("Arithmetic operation resulted in an overflow.") 但是,这会生成OverflowException :(“算术运算导致溢出。”)

So I tried this instead, 所以我尝试了这个

int[] arr = new int[UInt32.MaxValue/2];   //2^31  (i.e., 2 * 1024 * 1024 * 1024)

and it throws a 'System.OutOfMemoryException'. 并抛出“ System.OutOfMemoryException”。

What am I missing here, and what in fact is the largest integer array that I can create? 我在这里缺少什么,实际上我可以创建的最大整数数组是什么?


UPDATE: So, as it turns out, the largest array I can create is: 更新:事实证明,我可以创建的最大数组是:

int[] arr = new int[(long)(1.999 * 1024 * 1024 * 1024)]; //just shy of 2^31

So why can't I reach the limit that the documentation leads me to expect? 那么,为什么我不能达到文档所期望的极限?

From your link: 从您的链接:

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)。

You're exceeding that limit, still. 您仍然超出了该限制。

This should give a darn big array, though: 但是,这应该会给我们带来很大的麻烦:

int[,] arr = new int[UInt32.MaxValue/3,3];
//                 comes out even ^^^

The total size of that array, which contains the maximum number of elements, should be (16 GB - 4 bytes + metadata) Use an even larger value type to really put the hurt on your PC. 该数组的总大小(包含最大元素数)应为(16 GB-4字节+元数据)。使用更大的值类型将伤害真正地放在您的PC上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在.net 4.5项目上安装分析仪吗? - Can I have an analyzer on a .net 4.5 project? Eazfuscator.NET 3.3不支持.NET 4.5,但我仍然可以模糊我的.NET 4.5目标框架项目。 我不明白的是什么? - Eazfuscator.NET 3.3 does not support .NET 4.5, but I can still obfuscate my project that has .NET 4.5 target framework. What am I not understanding? 是什么会导致在.NET 4.5下完全正常的代码在3.5以下的情况下变得CPU贪婪呢? - What could cause code that's perfectly fine under .NET 4.5 to be CPU greedy under 3.5? 在.NET核心下的Linux上运行.NET 4.5 - Running .NET 4.5 on Linux under .NET core .net 4.5中的GZipStream类可以创建更大尺寸的文件吗? - Can GZipStream class in .net 4.5 create larger sized files? 在.NET4.5下使用ArrayList进行转换 - Casting Using ArrayList Under .NET4.5 如何在 Unity 5 中使用 .NET 框架 4.5 - How can I use .NET framework 4.5 in Unity 5 如何在.NET 4.5中“同时”运行这两种方法? - How can I run both of these methods 'at the same time' in .NET 4.5? .Net Framework 4.5中的数组的MaxSize - MaxSize of array in .Net Framework 4.5 我可以在 AWS Lambda 上使用 .Net Framework 4.5 部署 RESTful API 吗? - Can I deploy a RESTful API with .Net Framework 4.5 on AWS Lambda?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM