提升内存映射文件:读写访问

Boost Memory Mapped File : Read-Write Access

本文关键字:读写 写访问 文件 映射 内存      更新时间:2023-10-16

我正在初始化提升mapped_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;

当我打开文件大小的文件时,我得到一个 std::exception 显示"最多可以指定一个'模式和'标志"。我没有从 boost 文档中填充该模式,它说该模式已弃用。建议进一步的新代码应使用标志。

我的提升文件类型定义为

boost::iostreams::mapped_file _bioFile;

我尝试使用

_bioFile.open(param, filesize);

提升 IO 文档 : http://www.boost.org/doc/libs/1_57_0/libs/iostreams/doc/classes/mapped_file.html

我错过了什么吗?

对于那些想要答案的人,我能够用这段代码解决这个问题。

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