You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A self-contained, header-only, implementation of memory-mapped files in C++
for both reading and writing.
This is meant to offer the same capability of boost::mapped_file (source and sink) but avoiding
the dependance from boost.
Example usage.
#include<iostream>
#include"../include/mm_file/mm_file.hpp"intmain() {
std::string filename("./tmp.bin");
staticconstsize_t n = 13;
{
// write n uint32_t integers
mm::file_sink<uint32_t> fout(filename, n);
std::cout << "mapped " << fout.bytes() << " bytes "
<< "for " << fout.size() << " integers" << std::endl;
auto* data = fout.data();
for (uint32_t i = 0; i != fout.size(); ++i) {
data[i] = i;
std::cout << "written " << data[i] << std::endl;
}
fout.close();
}
{
// instruct the kernel that we will read the content// of the file sequentiallyint advice = mm::advice::sequential;
// read the stream as uint16_t integers
mm::file_source<uint16_t> fin(filename, advice);
std::cout << "mapped " << fin.bytes() << " bytes "
<< "for " << fin.size() << " integers" << std::endl;
autoconst* data = fin.data();
for (uint32_t i = 0; i != fin.size(); ++i) {
std::cout << "read " << data[i] << std::endl;
}
fin.close();
}
std::remove(filename.c_str());
return0;
}
See also the example in test/test.cpp. To compile that, just type the following commands from the parent directory.
$ cd test
$ mkdir build
$ cd build
$ cmake ..
$ make
About
A self-contained, header-only, implementation of memory-mapped files in C++ for fast integration into larger projects.