单个对象仍限制为2 GB的大小在CLR 4.0?大小、对象、GB、CLR

2023-09-02 10:15:01 作者:過客

据我了解有关于.NET单一实例的2 GB的限制。我没有付出了很多的关注,自从我主要的工作在32位操作系统为止。在32,但它是或多或少的人工限制反正。不过,我很惊讶地得知,这种限制也适用于64位.NET 。

As I understand it there's a 2 GB limit on single instances in .NET. I haven't paid a lot of attention to that since I have mainly worked on 32 bit OS so far. On 32 but it is more or less an artificial limitation anyway. However, I was quite surprised to learn that this limitation also applies on 64 bit .NET.

由于集合,如名单,其中,T> 使用数组存储项目,这意味着,在32位上运行的.NET应用程序将可以容纳两倍多相比在64位运行相同的应用程序列表中的参考类型的项目。这是相当惊人的海事组织。

Since collections such as List<T> use an array to store items, that means that a .NET application running on 32 bit will be able to hold twice as many reference type items in a list compared to the same application running on 64 bit. That is quite surprising imo.

有谁知道这限制述及CLR 4.0(我没有4.0安装在手的时刻)。

Does anyone know if this limitation is addressed in CLR 4.0 (I don't have a 4.0 installation at hand at the moment).

推荐答案

这更糟糕的是 - 你的进程空间中,当你工作在.NET中的32位比理论极限小得多。在32位.NET应用程序,我的经验是,你总是倾向于开始得到内存不足的错误某处大约内存使用1.2-1.4gb(有些人说他们可以得到1.6 ...但我从来没有看到)。当然,这不是在64位的系统中的问题。

It's worse than that - you're process space, when you're working in .NET in 32bit is much smaller than the theoretical limit. In 32bit .NET apps, my experience is that you'll always tend to start getting out of memory errors somewhere around 1.2-1.4gb of memory usage (some people say they can get to 1.6... but I've never seen that). Of course, this isn't a problem on 64bit systems.

话虽这么说,单条2GB数组引用类型,即使是在64位系统,是一个巨大的量的对象。即使在8个字节的引用,你必须要分配的268435456对象引用数组的能力 - (如果他们使用嵌套对象高达2GB,更多)每一个都可以是非常大的。这是更多的内存比以往任何时候都将真正需要的大多数应用程序。

That being said, a single 2GB array of reference types, even on 64bit systems, is a huge amount of objects. Even with 8 byte references, you have the ability to allocate an array of 268,435,456 object references - each of which can be very large (up to 2GB, more if they're using nested objects). That's more memory than would ever really be required by most applications.

其中 CLR团队成员的博客上讲述这个,与一些选择的方法来解决这些限制。在64位系统中,做一些像他BigArray&LT; T&GT;将是一个可行的解决方案来分配任意数量的对象到一个数组 - 超过2GB的单个对象的限制更多。 P /调用可以让您分配更大的阵列为好。

One of the members of the CLR team blogged about this, with some options for ways to work around these limitations. On a 64bit system, doing something like his BigArray<T> would be a viable solution to allocate any number of objects into an array - much more than the 2gb single object limit. P/Invoke can allow you to allocate larger arrays as well.

编辑:我应该提到这一点,以及 - 我不认为这种行为已经改变了在所有的.NET 4的行为一直以来.NET年初持平

I should have mentioned this, as well - I do not believe this behavior has changed at all for .NET 4. The behavior has been unchanged since the beginning of .NET.

编辑:.NET 4.5现在有64位的选项,以明确允许的对象是大于2GB通过设置gcAllowVeryLargeObjects在App.config。

.NET 4.5 will now have the option in x64 to explicitly allow objects to be larger than 2gb by setting gcAllowVeryLargeObjects in the app.config.