gpt4 book ai didi

c++ - 'boost::interprocess::basic_managed_shared_memory 中没有名为 'get_mapping_handle' 的成员

转载 作者:行者123 更新时间:2023-12-02 10:12:31 47 4
gpt4 key购买 nike

我正在尝试编译一些 boost 代码,但出现以下错误
这是代码的简化版本

#include <boost/interprocess/managed_shared_memory.hpp>
using namespace boost::interprocess;
int main()
{
managed_shared_memory shmem(create_only, "MySharedMemory", sizeof(TransferData));
mapped_region region(shmem, read_write);
}
但我得到了这个问题
In file included from holster/src/main.cc:6:
In file included from external/boost/boost/interprocess/managed_shared_memory.hpp:26:
In file included from external/boost/boost/interprocess/detail/managed_open_or_create_impl.hpp:26:
external/boost/boost/interprocess/mapped_region.hpp:594:39: error: no member named 'get_mapping_handle' in 'boost::interprocess::basic_managed_shared_memory<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, int, unsigned int, 0>, 0>, iset_index>'
mapping_handle_t map_hnd = mapping.get_mapping_handle();
~~~~~~~ ^
holster/src/main.cc:96:21: note: in instantiation of function template specialization 'boost::interprocess::mapped_region::mapped_region<boost::interprocess::basic_managed_shared_memory<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, int, unsigned int, 0>, 0>, iset_index> >' requested here
mapped_region region(shmem, read_write, 1000);
^
In file included from holster/src/main.cc:6:
In file included from external/boost/boost/interprocess/managed_shared_memory.hpp:26:
In file included from external/boost/boost/interprocess/detail/managed_open_or_create_impl.hpp:26:
external/boost/boost/interprocess/mapped_region.hpp:702:32: error: no member named 'get_mapping_handle' in 'boost::interprocess::basic_managed_shared_memory<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, int, unsigned int, 0>, 0>, iset_index>'
, mapping.get_mapping_handle().handle
~~~~~~~ ^
这是我正在使用的 boost 版本
Version: 1.71.0.0ubuntu2

最佳答案

这是一个极好的最小化示例。
它清楚地显示了你做错了什么。您正在托管段上使用映射区域。这不是他们的目的,甚至不是支持的:
enter image description here
Also:

Once created or opened, a process just has to map the shared memory object in the process' address space. The user can map the whole shared memory or just part of it. The mapping process is done using the mapped_region class. The class represents a memory region that has been mapped from a shared memory or from other devices that have also mapping capabilities (for example, files). A mapped_region can be created from any memory_mappable object and as you might imagine, shared_memory_object is a memory_mappable object [...]


我找不到明确的列表,但据我所知,这里是满足 memory_mappable 的模型列表。要求:
  • boost::interprocess::file_mapping
  • boost::interprocess::shared_memory_object
  • boost::interprocess::xsi_shared_memory

  • Besides, you're specifying sizeof(TransferData) for the segment and that's not gonna work in the first place: Why does boost::interprocess::managed_shared_memory throw a boost::interprocess_exception upon construction?

    关于c++ - 'boost::interprocess::basic_managed_shared_memory 中没有名为 'get_mapping_handle' 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62987782/

    47 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com