#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/unordered_map.hpp>
#include <boost/functional/hash.hpp>
#include <functional>
int main (int argc, char *argv[])
{
typedef int KeyType;
typedef float MappedType;
typedef std::pair<const int, float> ValueType;
typedef boost::interprocess::allocator<ValueType, boost::interprocess::managed_shared_memory::segment_manager> ShmAlloc;
typedef boost::unordered_map<KeyType, MappedType, boost::hash<KeyType>, std::equal_to<KeyType>, ShmAlloc> ShmHashMap;
boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create, "ContainerSharedMemory", 65536);
ShmHashMap *hash_map1 = segment.find_or_construct<ShmHashMap>("ShmHashMap1")(3, boost::hash<KeyType>(), std::equal_to<KeyType>(), segment.get_all
基于boost实现的共享内存版HashMap
最新推荐文章于 2022-06-17 16:27:17 发布
本文档展示了如何利用Boost库中的interprocess模块实现一个共享内存的HashMap。通过定义特定类型的allocator,可以在多个进程间共享存储数据的哈希映射。在示例中,创建了两个共享内存的HashMap实例,并进行插入和查找操作。
摘要由CSDN通过智能技术生成