-2

In my C# code, I need to include a matrix in size 13805*55223; which I believe is not that large.

To overcome RAM limitation, I am using gcAllowVeryLargeObjects, and I have also unchecked prefer 32-Bit system.

Doing all of that, I still face "Array dimension exceeds supported range" error!

I appreciate any help to handle this issue.

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
Mohamad S.
  • 21
  • 1
  • 2
  • can you show us your code – fubo Feb 10 '16 at 07:10
  • `13'805*55'223 = 762'353'515` so if you have as much as int values in that you will have ~ 3GB of memory used already... – Adwaenyth Feb 10 '16 at 07:16
  • 1
    Are you sure your app is really running at 64 bits? Try looking at [`Environment.Is64BitProcess`](https://msdn.microsoft.com/en-us/library/system.environment.is64bitprocess(v=vs.110).aspx) – xanatos Feb 10 '16 at 07:20
  • You are doing something wrong but it is going to take a psychic to guess what it might be. Just don't, use a jagged array. It not only avoids the limitation, it is also much faster. – Hans Passant Feb 10 '16 at 07:23
  • The code is simple like: double[,] a = new double[13805,55223]; – Mohamad S. Feb 10 '16 at 22:42
  • I have that much double actually, and it needs more than 3GB for sure. I have available RAM, but the problem is with array size. – Mohamad S. Feb 10 '16 at 22:43
  • I tested, and I am sure I am running at 64 bits. – Mohamad S. Feb 10 '16 at 22:44
  • If you use double values instead of int values, you need ~6GB of memory – tonirush Feb 11 '16 at 07:44

1 Answers1

3

Please try if the following program works on your system. It creates an onedimensional int array with the size 13805*55223. For these array size are ~3GB of memory reserved and works fine on my system.

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>
tonirush
  • 430
  • 1
  • 6
  • 14
  • Thank you Tonirush! I am just managing the error according to your suggestion now. The only change is that I had "gcAllowVeryLargeObjects" in a separate app.config, but now have all in a single app.config! I am not sure if that was the reason for my problem! – Mohamad S. Feb 10 '16 at 22:47
  • If you use double (64 bit value) instead of int (32 bit value), you need the double amount of memory (~6GB). – tonirush Feb 11 '16 at 07:40
  • So you need at least 8GB main memory, or better a system with 16GB main memory. I can't run a program that uses 6GB memory on my 8GB system because i have only 5GB free. – tonirush Feb 11 '16 at 08:07