Reputation: 14869
I am newbie to boost::iostream
memory mapped file and I am having some difficulties in understanding the classes.
I would like my function to create a new memory map file for writing and reading. I was successful for the writing part but I don't know how to read back the values.
Reading the docs it looks like the mapped_file_params::mode
param is ignored by both mapped_file_source
and mapped_file_sink
classes.
Possibly I would like to use it as it was a stream as I would like to use seekg
and read
.
If this is not possible what else can I use? Is it ok to use the mapped_file_sink::data()
to read back?
Below my code
namespace bip = boost::iostreams;
bio::mapped_file_params prm("data.out");
prm.new_file_size = 256; // in reality it will be bigger.
prm.mode = std::ios::in | std::ios::out;
bio::stream<bio::mapped_file_sink> ooo;
ooo.open(bio::mapped_file_sink(prm));
char AA;
AA = 'A';
ooo.write(&AA,1);
AA = 'B';
ooo.write(&AA,1);
char BB;
bio::seek(ooo,0,BOOST_IOS::beg);
ooo.read(&BB,1); // this fails
cout << B << endl;
Upvotes: 0
Views: 1811
Reputation: 20993
mapped_file_sink
is write only - this is why it ignores the mode parameter. mapped_file_source
is read only. To both read and write use mapped_file
.
Upvotes: 1