【发布时间】:2015-05-16 13:55:54
【问题描述】:
我想创建两个 200M int 元素数组。像这样:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Arr
{
class Program
{
static void Main(string[] args)
{
int Min = 0;
int Max = 10;
int ArrSize = 200000000;
int[] test2 = new int[ArrSize];
int[] test3 = new int[ArrSize];
Console.ReadKey();
}
}
}
但是,在 VS2013 下,我出现内存不足异常,黄色箭头指向 int[] test3 = new int[ArrSize]; 行。这台机器有 12GB 的 RAM。
如果我将元素数量减少到 150M,则不会引发异常。
如果我只初始化一个大小为 200M 的数组,则不会抛出异常。
为什么?
【问题讨论】:
-
不,这个问题在您发送的链接中没有答案。 200M 个整数大约是 800MB。为什么这个尺寸适合第一个对象,但不适合第二个对象?
-
这个问题绝对不是关于单个对象的大小,而是多个对象的总大小。重新打开。
-
@PetSerAl - 显然是 32 位的。 x64 将在大约 500M 的单次分配中失败,32 位在尝试找到 2 个 800Mb 的连续块时失败(这非常困难),通常一个还可以。