4

の内部で、両方のマップのキーを持って、値として別の内部boost::interprocess::managed_shared_memoryを作成しようとしています。共有メモリ セグメント内のこの Map in Map は、2 つの異なるプロセスによってアクセスされ、外部マップと内部マップの両方から値をフェッチします。boost::unordered_mapboost::unordered_mapstd::string

以下は私の実装であり、これが可能/正しい方法であるか、それとも他のより良い方法であるかを知りたいですか?

boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create, "BOOST_SHM", 65536);

    typedef std::string   KeyType;
    typedef std::string   ValueType;
    typedef std::pair<const KeyType, ValueType> MapType;
    typedef boost::interprocess::allocator<MapType, boost::interprocess::managed_shared_memory::segment_manager> ShmemAllocator;
    typedef boost::unordered_map<KeyType, ValueType, boost::hash<KeyType>, std::equal_to<KeyType>, ShmemAllocator> InMap;
    ShmemAllocator alloc_inst(segment.get_segment_manager());
    InMap *inside_map = segment.construct<InMap>("SHM_IN_MAP")(3, boost::hash<KeyType>(), std::equal_to<KeyType>(), alloc_inst);


    typedef std::pair<const KeyType, MapType> MIMType;
    typedef boost::interprocess::allocator<MIMType, boost::interprocess::managed_shared_memory::segment_manager> MIMShmemAllocator;
    typedef boost::unordered_map<KeyType, MapType, boost::hash<KeyType>, std::equal_to<KeyType>, MIMShmemAllocator> OutMap;
    //MIMShmemAllocator alloc_inst(segment.get_segment_manager());   /*Commented due to Error*/
    OutMap *outside_map = segment.construct<OutMap>("SHM_OUT_MAP")(3, boost::hash<KeyType>(), std::equal_to<KeyType>(), alloc_inst);

その他の詳細:

CentOS 7 上の gcc バージョン 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC)、BOOST_LIB_VERSION "1_58"

4

1 に答える 1