c# - What is the simple way to extend the use of array to prevent out of memory exception? -


float[][, , ,] tempdata = new float[30][, , ,];  private void inittempdata() {     const int focussize = 400;     try     {         (int = 0; < 30; i++)         {             tempdata[i] = new float[40, focussize, focussize, 5];         }     }     catch (outofmemoryexception ex)     {         messagebox.show(ex.message);     } } 

i need use tempdata array size of this:

tempdata[30][40, 400, 400, 5] 

but have experienced far, go outofmemory when define new array @ size more 100.

what idea think of is, initialize 4 new array size of 100. , use 4 new array starting different initial counter per below:

float[][, , ,] tempdata0 = new float[30][, , ,]; float[][, , ,] tempdata1 = new float[30][, , ,]; float[][, , ,] tempdata2 = new float[30][, , ,]; float[][, , ,] tempdata3 = new float[30][, , ,];  private void inittempdata() {     const int focussize = 100;     try     {         (int = 0; < 30; i++)         {             tempdata0[i] = new float[40, focussize, focussize, 5];             tempdata1[i] = new float[40, focussize, focussize, 5];             tempdata2[i] = new float[40, focussize, focussize, 5];             tempdata3[i] = new float[40, focussize, focussize, 5];         }     }     catch (outofmemoryexception ex)     {         messagebox.show(ex.message);     } }  //use tempdata0, tempdata1, tempdata2, , tempdata3 different initial counter (int = 0; < 30; i++) {     (int x = 0; x < focussize; x++)     {         (int z = 0; z < focussize; z++)         {             //use tempdata0 here         }     } }  (int = 0; < 30; i++) {     (int x = focussize; x < focussize * 2; x++)     {         (int z = focussize; z < focussize * 2; z++)         {             //use tempdata1 here         }     } }  (int = 0; < 30; i++) {     (int x = focussize * 2; x < focussize * 3; x++)     {         (int z = focussize * 2; z < focussize * 3; z++)         {             //use tempdata2 here         }     } } 

is above idea correct way of doing it? or there other option extend use of array?

that quite big array:

30 * 40 * 400 * 400 * 5 * (4 bytes) ~= 3.6gb total 

assuming have free memory , running 64bit process (required > 2/3gb), it's possible hitting wall because arrays laid out contiguous blocks in memory.

in example above using [30][40,400,400,5] you're asking clr find 30 128mb blocks of memory.

see: http://blogs.msdn.com/b/ericlippert/archive/2009/06/08/out-of-memory-does-not-refer-to-physical-memory.aspx

you try creating lists referencing smaller arrays, or declare 'jagged' array avoid contiguous memory issue (at cost of worst performance in dereferencing arrays of arrays).

i.e. float[30][40][400][400][5]


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -