简体   繁体   English

增强内存映射文件:读写访问

[英]Boost Memory Mapped File : Read-Write Access

I am initialising the boost mapped_file_params as shown below. 我正在初始化升压mapd_file_params,如下所示。

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". 当我使用文件大小打开文件时,我得到一个std :: exception,内容为“最多可以指定'mode和'flags之一”。 I have not populated the mode as from the documentation of boost, it says that mode is deprecated. 我没有从boost文档中填充该模式,它说该模式已被弃用。 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 增强IO文档: http : //www.boost.org/doc/libs/1_57_0/libs/iostreams/doc/classes/mapped_file.html

Am I missing something. 我错过了什么吗?

对于那些想要答案的人,我可以使用此代码解决问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM