【问题标题】:No member named 'get_mapping_handle' in 'boost::interprocess::basic_managed_shared_memory'boost::interprocess::basic_managed_shared_memory 中没有名为 'get_mapping_handle' 的成员
【发布时间】:2020-07-20 02:26:06
【问题描述】:

我正在尝试编译一些 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

【问题讨论】:

    标签: c++ boost


    【解决方案1】:

    这是一个极好的最小化示例。

    它清楚地显示了你做错了什么。您正在托管段上使用映射区域。这不是他们的目的,甚至不是支持:

    Also:

    一旦创建或打开,进程只需将共享内存对象映射到进程的地址空间。用户可以映射整个共享内存或只是其中的一部分。映射过程是使用 ma​​pped_region 类完成的。该类表示已从共享内存或其他具有映射功能的设备(例如文件)映射的内存区域。可以从任何 memory_mappable 对象创建 mapped_region,正如您可能想象的那样,shared_memory_object 是一个 memory_mappable 对象 [...]

    我找不到明确的列表,但据我所知,这里是满足memory_mappable 要求的模型列表:

    • boost::interprocess::file_mapping
    • boost::interprocess::shared_memory_object
    • boost::interprocess::xsi_shared_memory

    此外,您正在为细分指定 sizeof(TransferData),这首先是行不通的:Why does boost::interprocess::managed_shared_memory throw a boost::interprocess_exception upon construction?

    【讨论】:

    • 完美答案。非常感谢:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    相关资源
    最近更新 更多