【发布时间】:2015-02-24 16:48:06
【问题描述】:
我正在移植源代码以打开/读取/写入在多个进程之间共享的文件。它在 windows 下运行良好,因为它主要使用 boost::interprocess (1.44) 我没想到会有太多问题,但我发现了一些奇怪的东西:
//pseudo code
namespace bip = boost::interprocess;
namespace bipd = boost::interprocess::detail;
loop
bip::file_handle_t pFile = bipd::create_or_open_file(filename, bip::read_write);
bipd::acquire_file_lock(pFile);
// try to read bytes from pFile with 'read'
bipd::truncate_file(pFile, 0);
bipd::write_file(pFile, (const void*)(textBuffer)), bufLen);
当代码第一次运行时,它会创建文件并写入文本。文件模式是 ASCII (ASCII text, with very long lines),我可以阅读文本。
但是当循环第二次运行时,文件类型更改为
data,textBuffer 在文件中,但作为二进制数据!
我检查了boost/interprocess/details/os_file_functions.hpp,但没有找到导致这种行为的原因。
你有什么想法吗?
【问题讨论】:
标签: c++ linux file boost-interprocess