c++boostmemory-mapped-files

Boost Memory Mapped File : Read-Write Access


I am initialising the boost mapped_file_params as shown below.

mapped_file_params param;
param.path = _fileName.c_str();
param.flags = mapped_file::readwrite;
int nGranularity = mapped_file::alignment();
//! must be in multiples of Granularity.
param.offset =  5*nGranularity;

When I open the file with a filesize, I get an std::exception reading "at most one of 'mode and 'flags may be specified". I have not populated the mode as from the documentation of boost, it says that mode is deprecated. further new code should use flags is what is suggested.

My boost file type is defined as

boost::iostreams::mapped_file _bioFile;

I have attempted to open the file using

_bioFile.open(param, filesize);

boost IO documentation : http://www.boost.org/doc/libs/1_57_0/libs/iostreams/doc/classes/mapped_file.html

Am I missing something.


Solution

  • For those who want an answer, I was able to get around the problem with this code.

    _bioFile.open(_fileName.c_str(), std::ios_base::in | std::ios_base::out, filesize);