boost::interprocess::managed_shared_memory(2)(std::string)
#include <iostream>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/string.hpp>
using namespace std;
int main()
{
//boost::interprocess::shared_memory_object类是按照单个字节的方式读写共享内存,用起来不方便
boost::interprocess::shared_memory_object::remove("Highscore");
boost::interprocess::managed_shared_memory managed_shm(boost::interprocess::open_or_create, "Highscore", );//分配1024字节
//boost不能直接写入stl中的vector, map,string等,必须在boost::interprocess提供的另外一个分配器定义对应的数据类型,不是c++缺省的分配器
//创建一个分配器,内部使用的是"托管共享内存段管理器",段管理器负责管理位于共享内存内部的内存
typedef boost::interprocess::allocator<char, boost::interprocess::managed_shared_memory::segment_manager> CharAllocator;
//使用新建的分配器定义string对应的数据类型基于boost::interprocess::basic_stirng,经过分配器访问段管理器
typedef boost::interprocess::basic_string<char, std::char_traits<char>, CharAllocator> string;
//find_or_construct创建string实例需要知道那个段管理器被访问,所以段管理器指针作为构造函数的第二个指针
string* str = managed_shm.find_or_construct<string>("String")("Hello!", managed_shm.get_segment_manager());
str->insert(, " world");
cout << *str << endl;
getchar();
return ;
}
boost::interprocess::managed_shared_memory(2)(std::string)的更多相关文章
- boost::interprocess::managed_shared_memory(2)(std::deque)
struct shareDataEx : shareData { int index; int total_size; }; typedef managed_shared_memory::segmen ...
- boost::interprocess(1)
发送端:#include <iostream> #include <windows.h> #include <string> using namespace std ...
- boost::interprocess::shared_memory_object(1)(基本类型)
#include <iostream> #include <boost/interprocess/managed_shared_memory.hpp> struct pos2d ...
- boost信号量 boost::interprocess::interprocess_semaphore的用法
使用方法首先给信号量初始化赋值,可以根据需要设定需要的值,之前在写项目的过程中用这个控制下载的线程个数. boost::interprocess::interprocess_semaphore m_s ...
- HOW TO REPLACE ALL OCCURRENCES OF A CHARACTER IN A STD::STRING
From: http://www.martinbroadhurst.com/replacing-all-occurrences-of-a-character-in-a-stdstring.html T ...
- c++ istream转换为std::string
std::istreambuf_iterator<char> eos; std::string s(std::istreambuf_iterator<char>(stream) ...
- boost::interprocess(2)
//doc_anonymous_mutex_shared_data.hpp #include <boost/interprocess/sync/interprocess_mutex.hpp> ...
- How to convert a std::string to const char* or char*?
How to convert a std::string to const char* or char*? 1. If you just want to pass a std::string to a ...
- QString 和std::string互转
std::string cstr; QString qstring; //****从std::string 到QString qstring = QString(QString::fromLocal8 ...
随机推荐
- 一个简单的python爬虫(转)
# -*- coding: utf-8 -*- #--------------------------------------- # 程序:百度贴吧爬虫 # 版本:0.1 # 作者:why # 日期: ...
- 基于shiro+jwt的真正rest url权限管理,前后端分离
代码地址如下:http://www.demodashi.com/demo/13277.html bootshiro & usthe bootshiro是基于springboot+shiro+j ...
- iOS 九宫格手势密码
代码地址如下:http://www.demodashi.com/demo/11490.html 一.准备工作 需要准备什么环境 xcode,iOS8+ 本例子实现什么功能 主要实现手势密码设置,验证 ...
- Eclipse Debug 使用
Eclipse的debug模式:代码调试 * Eclipse或MyEclipse就是java的开发工具 * Eclipse开源的.免费的Java开发工具 * MyEclipse基于Eclipse开 ...
- memcache概念浅谈及名称混乱之区分
关于memcache这个现在应用广泛的组件,大大提高的网站的响应速度,也方便了程序开发缓存的应用.但是目前针对memcache,网上的资料 大同小异,尤其基于LAMP的网站居多,php/pcel又有两 ...
- [docker]docker日志驱动记录nginx日志情形探究
这里研究下容器nginx记录日志的集中情况,主要想弄明白,docker的日志--log-driver=fluentd 改成fluentd后,会不会在本地在记录一份日志 整体架构是这样的 情况1: 首先 ...
- C#将URL中的参数转换成字典Dictionary<string, string>
/// <summary> /// 将获取的formData存入字典数组 /// </summary> public static Dictionary<String, ...
- linux kvm 的虚拟机处于暂停状态怎么开机 和 KVM-Virsh指令
[root@ok home]# virsh list Id Name State ---------------------------------------------------- 13svn ...
- 380. Intersection of Two Linked Lists【medium】
Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...
- python学习之getpass模块
getpass模块提供两个功能: getpass.getpass(prompt ='Password:',stream = None) 提示用户输入密码而不回显. 使用字符串提示提示用 ...