c++ boost write memory mapped file -


i searching fast writing file using c++ , boost library. , use memory mapped file. example reading.
working simple. there string array. array elements 2 millions.

ofstream outfile("text.txt"); (int = 0; < 2000000; ++i) {     outfile << strarray[i] << "\n"; } outfile.close(); 

how can using memory mapped file? can find writing file using memory mapped file?

thank concerning.

you use boost iostreams mapped_file{_sink,_source} this.

although boost interprocess use mapped files, you'd better off using iostreams kind of raw access.

see http://www.boost.org/doc/libs/1_50_0/libs/iostreams/doc/classes/mapped_file.html

live on coliru

#include <boost/iostreams/device/mapped_file.hpp> #include <boost/iostreams/stream.hpp> #include <vector>  namespace bio = boost::iostreams;  int main() {     using namespace std;     vector<string> strarray(2000000);      bio::mapped_file_params params;     params.path          = "text.txt";     params.new_file_size = 30ul << 30;     params.flags         = bio::mapped_file::mapmode::readwrite;      bio::stream<bio::mapped_file_sink> out(params);      copy(strarray.begin(), strarray.end(), ostream_iterator<string>(out, "\n")); } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -