基于boost实现的共享内存版HashMap
来源:互联网 发布:音箱煲机软件 编辑:程序博客网 时间:2024/06/11 21:18
#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_allocator<ValueType>()); ShmHashMap *hash_map2 = segment.find_or_construct<ShmHashMap>("ShmHashMap2")(3, boost::hash<KeyType>(), std::equal_to<KeyType>(), segment.get_allocator<ValueType>()); for(int i = 0; i < 5; ++i) { ShmHashMap::iterator iter = hash_map1->find(i); if (iter != hash_map1->end()) { std::cout << "[ShmHashMap1]<" << i << ", " << iter->second << ">" << std::endl; iter->second += 1.0; } hash_map1->insert(ValueType(i, (MappedType)i)); } for(int i = 0; i < 5; ++i) { ShmHashMap::iterator iter = hash_map2->find(i); if (iter != hash_map2->end()) { std::cout << "[ShmHashMap2]<" << i << ", " << iter->second << ">" << std::endl; iter->second += 2.0; } hash_map2->insert(ValueType(i, (MappedType)i)); } return 0;}
0 0
- 基于boost实现的共享内存版HashMap
- 基于boost的共享内存系列-map
- 基于allocator实现的内存共享
- Boost IPC(interprocess)实现内存共享
- linux基于信号量同步的共享内存IPC实现
- 共享内存的实现
- nginx共享内存:共享内存的实现
- c++中用boost实现共享内存创建map容器
- 共享内存队列的实现
- 基于STL的共享内存技术
- 基于共享内存的key-value存储
- posix 基于文件的共享内存
- 基于共享内存的key-value存储
- 基于HashSet的HashMap的简单实现
- 基于Boost.MultiIndex实现的Session管理器
- 基于NETLINK的内核与用户空间共享内存的实现
- 基于NETLINK的内核与用户空间共享内存的实现
- 基于NETLINK的内核与用户空间共享内存的实现[转]
- 【CSS】扁平化都是纸老虎,看怎么抛弃前端框架在IE6扁平化
- ThinkPHP 学习笔记
- this 的工作原理
- TMCache + Mantle
- 裸机开发 的 中断初始化步骤
- 基于boost实现的共享内存版HashMap
- tornado template默认压缩空白字符导致coffee无法正确缩进
- MyEcplise怎么把本地jdk加进去
- tornado中使用celery实现异步MySQL操作
- tornado服务器session模块mongosion
- osgi_20150105
- Unix/Linux文件比较命令: comm命令, diff命令
- 开机出现 Grub error: unknown file system 的解决办法
- unity3D__总结