3

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++

2
  • Yes there is and I suppose it's pretty easy. Which part of its implementation you can't solve? (to read as: please if you need help first try your own then come here with code and specific questions). Commented Nov 18, 2013 at 14:37
  • 1
    Try searching for functions named... Um, I dunno... Perhaps read and write? Commented Nov 18, 2013 at 14:52

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

3 Comments

This is all great, is there a way to add compression too the BIN file was still large?
can you compress it too?
Use can use a compression library (e.g. zlib) and pass sections of the large buffer in a loop. Since you now treat the 2D array as a simple 1D buffer, it's no different than compressing any other data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.