c# - Fast load/save multidimensional array -


i need store/load possibly large ushort[,,], byte[,,] or double[,,] array.

i have tried naive approach scanning array element element filestream fs:

for (p = 0; p < planes; p++) {     (y = 0; y < height; y++)     {         (x = 0; x < width; x++)         {             fs.write(bitconverter.getbytes(array1[p, y, x]), 0, 8);         }     } } 

i have replaced loop binaryformatter, performs better:

bf.serialize(fs, array1); 

i ran small benchmark storing , loading 3 x 1024 x 768 array of doubles 10 times following results:

naive approach: 10 628 ms

binaryformatter approach: 8 722 ms

is there faster way? using pointers? serializing array one-dimensional , flushing file?

thanks suggestions.

use memorystream write data, , copyto filestream

ms.copyto(fs) 

it speed io operations hard drive


Comments