C#之数组索引范围
一般情况,C#数组仅支持2GB大小,对于int[]来讲,大概就是:2*1024*1024*1024/4=530870912,但实际上
比这个数值略小。
int bb = 536870897;
while (true)
{
bb++;
try
{
int[] aa = new int[bb];
}
catch
{
int[] cc = new int[bb / 2];
Console.WriteLine($"是{bb},{((double)bb) * 4.0 / 1024 / 1024 / 1024}GB");
break;
}
}
Console.ReadLine();

但是通过修改exe.config中的配置选项,可以将默认2GB大小,提高到8GB!

int bb = 536870897 * 4;
while (true)
{
bb++;
try
{
int[] aa = new int[bb];
}
catch
{
int[] cc = new int[bb / 2];
Console.WriteLine($"是{bb},{((double)bb) * 4.0 / 1024 / 1024 / 1024}GB");
break;
}
}
Console.ReadLine();

#####
愿你一寸一寸地攻城略地,一点一点地焕然一新
#####

浙公网安备 33010602011771号