I heard that there is a hard limit on the size of .Net Array
. It is said that the maximum amount of memory that can be allocated to any single instance of an Array
object ( regardless of whether it's int[]
, double[]
or your own array) is 2GB. And no, if you have a 64 bit machine, the 2GB limit is still there.
我听说.Net Array的大小存在硬性限制。据说,可以分配给Array对象的任何单个实例的最大内存量(无论是int [],double []还是您自己的数组)都是2GB。不,如果你有64位机器,2GB限制仍然存在。
I'm not sure whether my impression is correct or not. Anyone can confirm?
我不确定我的印象是否正确。有谁可以确认?
5 个解决方案
#1
13
That is correct. No single object can be larger than 2 GB.
那是对的。没有单个对象可以大于2 GB。
As with 32-bit Windows operating systems, there is a 2GB limit on the size of an object you can create while running a 64-bit managed application on a 64-bit Windows operating system.
与32位Windows操作系统一样,在64位Windows操作系统上运行64位托管应用程序时,可以创建的对象大小限制为2GB。
This question has additional details and some useful links: Single objects still limited to 2 GB in size in CLR 4.0?
此问题有其他详细信息和一些有用的链接:CLR 4.0中单个对象的大小仍然限制为2 GB?
#2
22
In versions of .NET prior to 4.5, the maximum object size is 2GB. From 4.5 onwards you can allocate larger objects if gcAllowVeryLargeObjects is enabled. Note that the limit for string
is not affected, but "arrays" should cover "lists" too, since lists are backed by arrays.
在4.5之前的.NET版本中,最大对象大小为2GB。从4.5开始,如果启用了gcAllowVeryLargeObjects,则可以分配更大的对象。请注意,字符串的限制不受影响,但“数组”也应该涵盖“列表”,因为列表由数组支持。
#3
4
You will run into a practical limit first - it is pretty impossible to get a 2gb array allocated. Practical limits I have encountered are around the 800mb mark AT PROGRAM START - going down drastically after that.
您将首先遇到实际限制 - 分配2gb数组是不可能的。我遇到的实际限制大约在800mb标记AT PROGRAM START - 之后大幅下降。
Anything larger than 64mb is a luck gamble on 32 bit - the large object heap is not defragmented, so you need 65mb free in one piece or allocation fails.
任何大于64mb的东西都是32位的运气赌博 - 大型对象堆没有进行碎片整理,所以你需要65mb一个免费或分配失败。
Theoretical limits are:
理论限制是:
- usable memory, especially under 32 bit.
- 可用内存,特别是在32位下。
- 32 bit number space for index (0 upward - no negative numbers for arrays UNLESS YOU PLAY SMART IN CREATION). You can create arrays allowing negative numbers, but not with C# standard syntax - only with reflection.
- 索引的32位数字空间(0向上 - 没有数组的负数,除非您在创建时使用SMART)。您可以创建允许负数的数组,但不能使用C#标准语法 - 仅使用反射。
- 2gb per object.
- 每个对象2gb。
But seriously, the practical implications are larger.
但严重的是,实际意义更大。
For .NET 4.0.... consider using memory mapped files ;)
对于.NET 4.0 ....考虑使用内存映射文件;)
#4
1
I would have thought that the limit might be on the index. I thought that index used has to be an integer so anything bigger than integer wouldn't work unless they have some way around that. So that would be 4294967296 elements. Not sure if this is even half true. I would like to know the answer myself.
我原本以为限制可能在索引上。我认为使用的索引必须是一个整数,所以任何大于整数的东西都不会起作用,除非他们有一些方法。那将是4294967296元素。不确定这是否真的是半真的。我想知道答案。
EDIT: As tomtom pointed out, integer is usually signed unless they using a non signed integer. So half of 4294967296 or 2147483648 roughly.
编辑:正如tomtom所指出的,整数通常是有符号的,除非它们使用非有符号整数。所以一半是4294967296或2147483648。
#5
0
Hope this help: http://blogs.msdn.com/joshwil/archive/2005/08/10/450202.aspx
希望这个帮助:http://blogs.msdn.com/joshwil/archive/2005/08/10/450202.aspx
i.e.
即
- It uses int as index, which has max value = 2,147,483,647 (2GB)
- 它使用int作为索引,其最大值= 2,147,483,647(2GB)
- Its by design. 2.
- 它的设计。 2。
#1
13
That is correct. No single object can be larger than 2 GB.
那是对的。没有单个对象可以大于2 GB。
As with 32-bit Windows operating systems, there is a 2GB limit on the size of an object you can create while running a 64-bit managed application on a 64-bit Windows operating system.
与32位Windows操作系统一样,在64位Windows操作系统上运行64位托管应用程序时,可以创建的对象大小限制为2GB。
This question has additional details and some useful links: Single objects still limited to 2 GB in size in CLR 4.0?
此问题有其他详细信息和一些有用的链接:CLR 4.0中单个对象的大小仍然限制为2 GB?
#2
22
In versions of .NET prior to 4.5, the maximum object size is 2GB. From 4.5 onwards you can allocate larger objects if gcAllowVeryLargeObjects is enabled. Note that the limit for string
is not affected, but "arrays" should cover "lists" too, since lists are backed by arrays.
在4.5之前的.NET版本中,最大对象大小为2GB。从4.5开始,如果启用了gcAllowVeryLargeObjects,则可以分配更大的对象。请注意,字符串的限制不受影响,但“数组”也应该涵盖“列表”,因为列表由数组支持。
#3
4
You will run into a practical limit first - it is pretty impossible to get a 2gb array allocated. Practical limits I have encountered are around the 800mb mark AT PROGRAM START - going down drastically after that.
您将首先遇到实际限制 - 分配2gb数组是不可能的。我遇到的实际限制大约在800mb标记AT PROGRAM START - 之后大幅下降。
Anything larger than 64mb is a luck gamble on 32 bit - the large object heap is not defragmented, so you need 65mb free in one piece or allocation fails.
任何大于64mb的东西都是32位的运气赌博 - 大型对象堆没有进行碎片整理,所以你需要65mb一个免费或分配失败。
Theoretical limits are:
理论限制是:
- usable memory, especially under 32 bit.
- 可用内存,特别是在32位下。
- 32 bit number space for index (0 upward - no negative numbers for arrays UNLESS YOU PLAY SMART IN CREATION). You can create arrays allowing negative numbers, but not with C# standard syntax - only with reflection.
- 索引的32位数字空间(0向上 - 没有数组的负数,除非您在创建时使用SMART)。您可以创建允许负数的数组,但不能使用C#标准语法 - 仅使用反射。
- 2gb per object.
- 每个对象2gb。
But seriously, the practical implications are larger.
但严重的是,实际意义更大。
For .NET 4.0.... consider using memory mapped files ;)
对于.NET 4.0 ....考虑使用内存映射文件;)
#4
1
I would have thought that the limit might be on the index. I thought that index used has to be an integer so anything bigger than integer wouldn't work unless they have some way around that. So that would be 4294967296 elements. Not sure if this is even half true. I would like to know the answer myself.
我原本以为限制可能在索引上。我认为使用的索引必须是一个整数,所以任何大于整数的东西都不会起作用,除非他们有一些方法。那将是4294967296元素。不确定这是否真的是半真的。我想知道答案。
EDIT: As tomtom pointed out, integer is usually signed unless they using a non signed integer. So half of 4294967296 or 2147483648 roughly.
编辑:正如tomtom所指出的,整数通常是有符号的,除非它们使用非有符号整数。所以一半是4294967296或2147483648。
#5
0
Hope this help: http://blogs.msdn.com/joshwil/archive/2005/08/10/450202.aspx
希望这个帮助:http://blogs.msdn.com/joshwil/archive/2005/08/10/450202.aspx
i.e.
即
- It uses int as index, which has max value = 2,147,483,647 (2GB)
- 它使用int作为索引,其最大值= 2,147,483,647(2GB)
- Its by design. 2.
- 它的设计。 2。