提升托管映射文件std :: unordered_map Linux分段错误

时间:2020-02-10 15:09:55

标签: linux boost segmentation-fault unordered-map interprocess

我正在尝试使用boost进程映射std :: unordered_map。 使用Windows,一切正常。在Linux上,我遇到了分段错误。

    using namespace boost::interprocess;

    struct State {
        uint8_t state = 0;

        State(uint8_t _state) {
            state = _state;
        }
    };

    managed_mapped_file file(open_or_create, "MySharedMemory", 65536);

    typedef uint32_t KeyType;
    typedef State  MappedType;
    typedef std::pair<const KeyType, MappedType> ValueType;
    typedef boost::interprocess::allocator<ValueType, boost::interprocess::managed_mapped_file::segment_manager> UnorderedMapAllocator;
    typedef boost::unordered_map<KeyType, MappedType, boost::hash<KeyType>, std::equal_to<KeyType>, UnorderedMapAllocator> unordered_map;

    unordered_map* map = file.find_or_construct<unordered_map>("fault_states")(3, boost::hash<KeyType>(), std::equal_to<KeyType>(), file.get_segment_manager());

    uint32_t size = (uint32_t)map->size();
    for (uint32_t i = size; i < size + 100; ++i) {
        State state(46);
        map->insert(ValueType(i, state));
    }

    for (auto x : *map) {
        std::cout << x.first << " ";
        std::cout << x.second.state << std::endl;
    }

在第一次运行时,一切正常。在第二次运行中,我得到了细分错误。 如果我使用boost :: unordered_map,那么一切正常,但是我必须使用std版本

提升版本1.6.4 Gcc版本7.4.0

0 个答案:

没有答案
相关问题