All around the Internet, people are asking "What is the fastest way to read files?". Let's make our task for this recipe even harder: what is the fastest and portable way to read binary files?
The technique from this recipe is widely used by applications critical to input and output performance. It's the fastest way to read files:
- We need to include two headers from the
Boost.Interprocess
library:
#include <boost/interprocess/file_mapping.hpp> #include <boost/interprocess/mapped_region.hpp>
- Now, we need to open a file:
const boost::interprocess::mode_t mode = boost::interprocess::read_only; boost::interprocess::file_mapping fm(filename, mode);
- The main part of this recipe is mapping all the files to memory:
boost::interprocess::mapped_region region(fm, mode, 0, 0);
- Getting a pointer to the data in the file:
const char* begin = static_cast<const char...