小编Ell*_*ark的帖子

在共享内存中使用boost :: interprocess allocator的std :: unordered_map - 缺点?

我现在正在使用共享内存boost::interprocess.

我已经按以下方式定义了一些std::unordered_mapstd::unordered_set类型:

#include <boost/interprocess/allocators/allocator.hpp>

#include <unordered_map> // NOT the boost implementation ...

...

namespace ipc = boost::interprocess;

 /**
 * allocator type needed to construct maps in shared memory
 */
typedef ipc::allocator<std::pair<const size_t, std::string>,
           ipc::managed_shared_memory::segment_manager> OBJ_MAP_ALLOCATOR;

/**
 * map type to construct maps in shared memory
 */
typedef std::unordered_map<size_t,
               std::string,
               std::hash<size_t>,
               std::equal_to<size_t>,
               OBJ_MAP_ALLOCATOR> OBJ_MAP_TYPE;
Run Code Online (Sandbox Code Playgroud)

我把它们初始化为:

ipc::managed_shared_memory segment;

// allocate segment etc ... 

OBJ_MAP_ALLOCATOR alloc_inst(segment.get_segment_manager());
objMap = segment.find_or_construct<OBJ_MAP_TYPE> (ipc::unique_instance)(alloc_inst);
Run Code Online (Sandbox Code Playgroud)

这似乎工作正常,我没有在编译或运行时(在Apple LLVM version 9.1.0 (clang-902.0.39.1)使用C++ …

c++ containers boost stl interprocess

3
推荐指数
1
解决办法
526
查看次数

标签 统计

boost ×1

c++ ×1

containers ×1

interprocess ×1

stl ×1