I have a binary file in which I save the following variables millions of times:
- a x-size vector of floats
- two unsigned integers
Currently I'm using ifstream for opening and reading the file but I was wondering if I could speed up the execution time by loading the whole file into memory and reducing the I/Os.
How can I load the file into memory and then convert it into the variables I want? With ifstream this is done easily but I don't know how to buffer it and then extract the data.
This is the code I'm using to save the data:
osfile.write(reinterpret_cast<const char*> (&sz), sizeof(int));// Size of vector
osfile.write(reinterpret_cast<const char*> (&vec[0]), sz*sizeof(float));
osfile.write(reinterpret_cast<const char*> (&a), sizeof(unsigned int));
osfile.write(reinterpret_cast<const char*> (&b), sizeof(unsigned int));