I need to save a large 3D array of integers into a file, and load it again in C++. It is 256*256*256 = 16777216 integers.
What is the best way to save this and load it again? I am mostly interested in a quick load time.
I need to save a large 3D array of integers into a file, and load it again in C++. It is 256*256*256 = 16777216 integers.
What is the best way to save this and load it again? I am mostly interested in a quick load time.
If the array is allocated in contiguous memory (i.e.: you don't allocate each dimension separately) - you can just dump the whole memory block to file. It takes as much as it takes, but that would be the least overhead (i.e.: call binary write on the whole chunk of data).
If you're saving on one system and loading on another, you might have issues with data representation, in this case you'd probably want to serialize the array and save each value in a controlled matter.
You may be interested in Boost.Serialization, particularly if you (1) want the ability to easily store such data on disk, (2) want a coherent way to save more complex objects, and (3) want a solution that's portable.