I'm developing a C++ application whose output is a single big binary file (a couple of GBs, basically a large sequence of floats). The content of this file is generated asynchronoulsy by parallel processes.
Each time a process finishes, its result has to be saved to its corresponding position inside the binary file in the disk (the order in which processes finish does not necessarily correspond to the order in which their results are to be stored in the disk. It takes about 5 processes to get the full data for the output).
What would be the best way to achieve this in C++? I have a couple solutions that work, but maybe they can be improved in terms of minimizing disk usage:
- Saving individual files for each finished process, then merging
- Keeping a fstream open and positioning the put pointer for each save operation using seekp()