Quote Originally Posted by Fede View Post
The binary file is data generated by a colleague with a pre-defined format: raw array of NormalizedPair.
It was not clear in my first post but I am actually using a std::vector<NormalizedPair>. The problem I was afraid of comes from the fact that the data was generated with an unknown version of the g++ compiler in a random OS and I am now reading the data with g++9 in Linux.
I thought alignment could become an issue even though we are using the same struct.

In the future I will have control over the generation of the data. For that case I will check SQLite. Is SQLite recommended over HDF5? The end result will be always the same, I want to consistently load the binary/SQLite/HDF5 data into an std::vector<NormalizedPair>. This is because I want to use a set of processing functions which takes as inputs C++ containers (user-defined but also std algorithms). Actually I should read more about SQLite API, maybe I can use it directly without needing a C++ container.

If you don't have control over the output file then your only real choice is to read it in binary and just do trial and error adjustments to account for alignment, data-widths, endian-ness, and padding.

Otherwise, I'd recommend using a serialization library. A good one will pack the data pretty efficiently.

You could also go with plain text files. Not nearly as compact but much easier to code up. For something like that, fprintf() and fscanf() for example could be used.