Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading and Writing a large multi-dimensional array to binary file and back into array during execution?

I have a large multi-dimensional array: float largetable[32][256][128][3]

Is there a way to write this array to a binary file and read it back to the array easily in C++?

In VS2013 when I have the data array in a header file (which is not great form) but get a : fatal error C1060: compiler is out of heap space

So I figure reading it in and out is the way to go.

I'm a python programmer, so I'm relatively new to C++

like image 723
John Du Avatar asked Feb 28 '26 18:02

John Du


1 Answers

use the fwrite() function to write the entire array in one shot:

FILE* pFile = fopen("filename", "wb");
fwrite(largetable, sizeof(largetable), 1, pFile);
fclose(pFile);

reading it back:

FILE* pFile = fopen("filename", "rb");
fread(largetable, sizeof(largetable), 1, pFile);
fclose(pFile);
like image 129
egur Avatar answered Mar 04 '26 20:03

egur