#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)的更多相关文章

  1. boost::interprocess::managed_shared_memory(2)(std::deque)

    struct shareDataEx : shareData { int index; int total_size; }; typedef managed_shared_memory::segmen ...

  2. boost::interprocess(1)

    发送端:#include <iostream> #include <windows.h> #include <string> using namespace std ...

  3. boost::interprocess::shared_memory_object(1)(基本类型)

    #include <iostream> #include <boost/interprocess/managed_shared_memory.hpp> struct pos2d ...

  4. boost信号量 boost::interprocess::interprocess_semaphore的用法

    使用方法首先给信号量初始化赋值,可以根据需要设定需要的值,之前在写项目的过程中用这个控制下载的线程个数. boost::interprocess::interprocess_semaphore m_s ...

  5. 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 ...

  6. c++ istream转换为std::string

    std::istreambuf_iterator<char> eos; std::string s(std::istreambuf_iterator<char>(stream) ...

  7. boost::interprocess(2)

    //doc_anonymous_mutex_shared_data.hpp #include <boost/interprocess/sync/interprocess_mutex.hpp> ...

  8. 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 ...

  9. QString 和std::string互转

    std::string cstr; QString qstring; //****从std::string 到QString qstring = QString(QString::fromLocal8 ...

随机推荐

  1. iOS开发一个制作Live Photo的工具

    代码地址如下:http://www.demodashi.com/demo/13339.html 1.livePhoto简介 livePhoto是iOS 9.0 之后系统相机提供的拍摄动态照片的功能,但 ...

  2. 单元测试JUnit 4(二)——keeps the bar green to keeps the code clean

    1.Failure和Error Failure是指测试失败  Error是指测试程序本身出错  (int a=10/0) 2.JUnit常用注解 2.1 @RunWith: 可以更改测试运行器(继承o ...

  3. github创建maven项目过程

    笔者运行环境: 1. windows 10 2. cygwin,安装openssh 3. git版本 2.11.0 前置操作,如果已经配置可以略过 1.  cygwin下执行 ssh-keygen - ...

  4. js检测回车符

    在说检测回车符之前,需要了解keydown和keypress的区别 比如你可以将检测事件绑定在input上,如下所示: <input name="remark" id=&qu ...

  5. Actors编程模型

    Actors模型(Actor model)首先是由Carl Hewitt在1973定义, 由Erlang OTP (Open Telecom Platform) 推广,其 消息传递更加符合面向对象的原 ...

  6. 关闭MongoDB

    以下方法干净地关闭MongoDB: 完成所有挂起的操作.刷新数据到数据文件.关闭所有的数据文件 1. > use admin switched to db admin > db.shutd ...

  7. Memcache集群安装与配置

    Memcache集群的安装和配置 :http://blog.163.com/asd_wll/blog/static/210310402013084405481/

  8. Spark-shell 无法启动之网络问题

    由于需要首次手动安装sbt,需要联网,故将虚拟机的网络适配器模式设置为"桥接模式",这样就可以和互联网相连接. 但是后面执行"spark-shell  --master ...

  9. Eclipse Jetty Integration

    http://eclipse-jetty.sourceforge.net/ Introduction Eclipse Jetty Integration provides a launch confi ...

  10. (WPF)依赖属性

    属性触发器: <Button MinWidth=" 75" Margin="10"> <Button.Style> <Style ...