c++ - boost 共享内存 : the volume of a file has been externally altered and open file is not longer valid

标签 c++ boost vector shared-memory

我正在使用 Boost shared memory 在不同进程之间共享 vector 。然而,在某些情况下,共享内存的消费者会抛出这个异常:

Unexpected exception: The volume for a file has been externally altered so that the opened file is no longer valid.

我设置了适当的同步机制。此错误可能表明什么?


已解决其中一个进程在创建时未正确分配内存大小。

When a shared memory object is created, its size is 0. To set the size of the shared memory, the user must use the truncate function call, in a shared memory that has been opened with read-write attributes

来源 - Boost shared memory

最佳答案

这意味着文件的体积已被外部更改。查找写入文件的其他进程。

换句话说,这意味着您没有适当的同步。

你用bip::managed_mapped_file::grow吗?在任何情况下?文档说明它只允许离线增长。

关于c++ - boost 共享内存 : the volume of a file has been externally altered and open file is not longer valid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30122125/

相关文章:

c++ - 传递给函数的 vector 没有被修改

c++ - FastCGI 清理代码在 Windows 下不起作用

c++ - 类中枚举类的运算符重载

c# - C# 中的 Char * 编码

c++ - Boost 程序选项,空字符串处理

vector - 重复长度与输入向量不同的排列

c++ - 如何在没有条件的情况下更新直方图?

c++ - 我可以在 qt Creator 中使用带有 try catch 语句的断点吗?

c++ - 如何转移 boost::ptr_vector 元素的所有权?

c++ - 使用 boost::chrono 计算执行时间