开发者

interprocess map versus map/unordered_map

There 开发者_开发技巧are a lot of discussions about the differences between std::map and boost::unordered_map. But what about boost::interprocess::map ?

Did somebody perform perfomance tests between boost::interprocess::map and std::map ?

I haven't used interprocess::map so much but i have the feeling that above 1M elements, it becomes really slow.

Thanks


Boost interprocess containers are standard containers with custom allocators.

Reason: when two processes share memory, the memory is mapped to different addresses in the two processes. To be able to use pointers to shared memory objects, one must not use absolute addresses but relative offsets (which are identical in both processes).

So the allocator classes relevant to boost::interprocess involve extra arithmetic at dereferenciation. They define a custom pointer type which is slightly heavier to use than normal pointers.

Apart from that, the containers are exactly the same as the standard ones. Same complexity, and only a slight overhead at element access (an extra addition). The differences between map and unordered_map for instance will be reflected as is in when using the special interprocess allocator.


That is not a meaningful comparison. They are used for totally different purposes.

interprocess::map is used for sharing data between process. std::map is used inside a single processes.


There is this comment in file boost/interprocess/containers/container/map.hpp:

// This file comes from SGI's stl_map/stl_multimap files. Modified by Ion Gaztanaga.
// Renaming, isolating and porting to generic algorithms. Pointer typedef 
// set to allocator::pointer to allow placing it in shared memory.

So the preformance differences just come from the difference in performance of the used allocators which depend on the kind of sharing and the operating system.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜