Say we have a struct of an int array, a float array etc. and we need to write them into a binary format file for fast reloading. Can this be done in a simple way?
Should the files be several for each of the array?
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.
Unless you have a huge amount of data, just write a standard text format. If you can assume c99 on both ends, use the
%aformatter for floating-point data to insulate yourselves from the vagaries of binary-decimal conversion.If the amount of data is huge, or you need to use a “raw data” format for other reasons, you will want to convert your data into a known endianness before writing, and convert back to the host endianness after reading. Any reasonably sane OS has library routines for doing these conversions.