加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何创建一个包含超过300万个数据的数组

发布时间:2020-12-16 02:00:35 所属栏目:百科 来源:网络整理
导读:参见英文答案 Why am I getting an Out Of Memory Exception in my C# application?????????????????????????????????????7个 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace
参见英文答案 > Why am I getting an Out Of Memory Exception in my C# application?????????????????????????????????????7个

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;

        }
    }
}

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

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

解决方法

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

By default,when you run a 64-bit managed application on a 64-bit Windows operating system,you can create an object of no more than 2 gigabytes (GB). However,in the .NET Framework 4.5,you can increase this limit. For more information,see the gcAllowVeryLargeObjects element.

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

<configuration>
  <runtime>
    <gcAllowVeryLargeObjects enabled="true" />
  </runtime>
</configuration>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读