IntArray for doubleArray, Out Of Memory Exception C #

I am trying to convert an array of 10,000 to 10,000 int for a double array with the following method (I found on this site)

public double[,] intarraytodoublearray( int[,] val){ 

        int rows= val.GetLength(0);
        int cols = val.GetLength(1);
        var ret = new double[rows,cols];
        for (int i = 0; i < rows; i++ )
        {

            for (int j = 0; j < cols; j++) 
            {
                ret[i,j] = (double)val[i,j];
            }
        }
        return ret;
}

and the way I'm calling

 int bound0 = myIntArray.GetUpperBound(0);
 int bound1 = myIntArray.GetUpperBound(1);
 double[,] myDoubleArray = new double[bound0,bound1];  
 myDoubleArray = intarraytodoublearray(myIntArray)  ;

he gives me this error

Unhandled Exception: OutOfMemoryException
[ERROR] FATAL UNHANDLED EXCEPTION: System.OutOfMemoryException: Out of memory
at (wrapper managed-to-native) object:__icall_wrapper_mono_array_new_2 (intptr,intptr,intptr)

The device has 32 GB of RAM, OS - MAC OS 10.6.8

+5
source share
1 answer

Well, you are trying to create an array of 100 million doublings (each of which will take 800 MB) - twice:

// This line will allocate an array...
double[,] myDoubleArray = new double[bound0,bound1];  
// The method allocates *another* array...
myDoubleArray = intarraytodoublearray(myIntArray);

Why try to initialize with myDoubleArrayan empty array and then reassign the value? Just use:

double[,] myDoubleArray = intarraytodoublearray(myIntArray);

, . , , ... , Mono . , , 64- . :

gmcs -platform:x64 ...

( , . , .)

, intarraytodoublearray - - int Int32 . Int32ArrayToDoubleArray .

+5

All Articles