如何使用超过300百万的数据创建一个数组

use*_*567 3 c# memory-management out-of-memory

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace testes
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64[] a = new Int64[300000000];
            a[0] = 10;

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

运行此代码后,我收到一个System.OutOfMemoryException但我的计算机有8千兆ram免费.请你帮助我好吗?

我是C#的初学者.我已经将编译目标cpu更改为x64,认为只有这个就足够了.谢谢吕克

Lee*_*ary 5

http://msdn.microsoft.com/en-us/library/ms241064(v=vs.110).aspx

默认情况下,在64位Windows操作系统上运行64位受管应用程序时,可以创建不超过2千兆字节(GB)的对象.但是,在.NET Framework 4.5中,您可以增加此限制.有关更多信息,请参阅gcAllowVeryLargeObjects元素.

拆分数组或将其放入配置中:

<configuration>
  <runtime>
    <gcAllowVeryLargeObjects enabled="true" />
  </runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)