我正在使用 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/