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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.