I am trying to convert a 10,000 by 10,000 int array to double array with the following method (I found in this website)
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 call is
int bound0 = myIntArray.GetUpperBound(0);
int bound1 = myIntArray.GetUpperBound(1);
double[,] myDoubleArray = new double[bound0,bound1];
myDoubleArray = intarraytodoublearray(myIntArray) ;
it 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 machine has 32GB RAM, OS is MAC OS 10.6.8
Well, you’re trying to create an array of 100 million doubles (each of which will take 800MB) – twice:
Why bother initializing
myDoubleArrayto an empty array and then reassigning the value? Just use:That will halve the amount of memory used for one thing. Now whether or not it’ll work at that point, I’m not sure… it depends on how Mono deals with large objects and memory. If you’re using a lot of memory, you definitely want to make sure you’re using a 64-bit VM. For example:
(The important assembly to compile with this option is the main application which will start up the VM. It’s not clear what kind of application you’re writing.)
As an aside,
intarraytodoublearrayis a horrible name – it uses the aliasintinstead of the frameworkInt32name, and it ignores the capitalization conventions.Int32ArrayToDoubleArraywould be better.