gcallowverylargeobjects没有解决C#中的维度限制

时间:2016-02-10 07:09:04

标签: c# arrays dimensions gcallowverylargeobjects

在我的C#代码中,我需要包含一个大小为13805 * 55223的矩阵;我认为不是那么大。

为了克服RAM限制,我使用gcAllowVeryLargeObjects,我也取消选中了偏好的32位系统。

完成所有这些操作后,我仍然面临“阵列尺寸超出支持范围”错误!

我感谢您处理此问题的任何帮助。

1 个答案:

答案 0 :(得分:3)

请尝试以下程序在您的系统上运行。 它创建一个大小为13805 * 55223的onedimensional int数组。 对于这些数组大小,保留约3GB的内存,并在我的系统上正常工作。

的Program.cs:

using System;

namespace arrtest
{
    class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Is64BitProcess :"+  Environment.Is64BitProcess);
            int [] arr = new int[13805*55223];
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

的app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
    </startup>
    <runtime>
        <gcAllowVeryLargeObjects enabled="true" />
    </runtime>
</configuration>