boost::interprocess(1)
发送端:
#include <iostream>
#include <windows.h>
#include <string>
using namespace std; #include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <thread> using namespace boost::interprocess;
int num = ;
mapped_region *mp_r; void funs()
{
while ()
{
num ++;
memcpy(mp_r->get_address(), &num, sizeof(int));
mp_r->get_address();
Sleep();
} }
int main(int argc, char*argv[])
{
shared_memory_object share_obj(create_only, "named_obj", read_write);
share_obj.truncate(sizeof(int));
mp_r = new mapped_region(share_obj, read_write); std::thread th(funs);
th.detach();
getchar();
return ;
}
接收端:
#include <iostream>
#include <string>
#include <windows.h>
using namespace std; #include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <thread> using namespace boost::interprocess;
mapped_region* mp_r; void fung()
{
while ()
{
int num = ;
memcpy(&num, static_cast<char*>(mp_r->get_address()), sizeof(int));
cout<<num<<endl;
Sleep();
}
} void main(int argc, char *argv[])
{
//open shared memory object
shared_memory_object share_obj(open_only, "named_obj", read_only);//map the shared memory object to current process
mp_r = new mapped_region(share_obj, read_only);
std::thread th(fung);
th.detach();
getchar();
//remove shared memory object
shared_memory_object::remove("named_obj"); }
boost::interprocess(1)的更多相关文章
- boost信号量 boost::interprocess::interprocess_semaphore的用法
使用方法首先给信号量初始化赋值,可以根据需要设定需要的值,之前在写项目的过程中用这个控制下载的线程个数. boost::interprocess::interprocess_semaphore m_s ...
- boost::interprocess(2)
//doc_anonymous_mutex_shared_data.hpp #include <boost/interprocess/sync/interprocess_mutex.hpp> ...
- boost::interprocess::managed_shared_memory(2)(std::deque)
struct shareDataEx : shareData { int index; int total_size; }; typedef managed_shared_memory::segmen ...
- boost::interprocess::managed_shared_memory(2)(std::string)
#include <iostream> #include <boost/interprocess/managed_shared_memory.hpp> #include < ...
- boost::interprocess::shared_memory_object(1)(基本类型)
#include <iostream> #include <boost/interprocess/managed_shared_memory.hpp> struct pos2d ...
- Boost.Interprocess
https://github.com/svebert/InterprocessMsg 好像消息队列
- Boost IPC Persistence Of Interprocess Mechanisms 例子
下面这一段摘抄自 Boost 1_55_0 的文档,显然标注了 每一个的生命期. One of the biggest issues with interprocess communication m ...
- 用boost共享内存实现进程通信的例子
发送端 #include "DBProc1.h" #include <string> #include <thread> #include <boos ...
- 详解boost库中的Message Queue .
Message Queue(后文简写成MQ或消息队列)是boost库中用来封装进程间通信的一种实现,同一台机器上的进程或线程可以通过消息队列来进行通迅.消息队列中的消息由优先级.消息长度.消息数据三部 ...
随机推荐
- kettle--组件(1)--值映射
组件:值映射 如下如所示: 首先,给出官方给出的文档: 个人理解: Target field name:可以理解为将source column的字段复制为另一个target column的名字. De ...
- golang使用sqlite
安装问题 在import sqlite的时候,golang build 出现以下错误, exec: "gcc": executable file not found in %PAT ...
- python导入模块的两种方式
第一种 from support import * 这种方式导入后可以直接调用(有命名冲突问题)命名冲突后定义的覆盖前定义的 如果在函数导入前定义 则导入函数覆盖 否则相反 if __name__ = ...
- C# 异或校验算法
C# 的异或校验算法 直接上代码 public partial class FormCRC : Form { public FormCRC() { InitializeComponent(); } p ...
- codesmith 自动生成C# model 实体模板
<%-- Name:自动生成 Author: 陈胜威 Description: 直接生成model类 --%> <%@ Template Language="C#" ...
- WCF实现客户端和服务端
service side 1.定义ServiceContract: 2.new a ServiceHost 3. add endpoint using System.ServiceModel; nam ...
- Freeswitch中文用户手册(第四章 SIP)----2
通过 B2BUA 呼叫 在真实世界中,bob 和 alice 肯定要经常改变位置,那么它们的 SIP 地址也会相应改变,并且,如果他们之中有一个或两个处于 NAT 的网络中时,直接通信就更困难了.所以 ...
- Spring Boot(三):logback打印日志
springboot对logback的支持是非常好的,不需要任何配置,只需要在resource下加logback.xml就可以实现功能直接贴代码: <?xml version="1.0 ...
- SYN攻击防护措施
SYN攻击的应对措施 针对SYN攻击的几个环节.提出对应的处理方法: 方式1:降低SYN-ACK数据包的重发次数(默认是5次): sysctl -w net.ipv4.tcp_synack_retri ...
- PHP学习笔记(5)GD库画验证码
<?php header("content-type:image/png"); $width = 500; $height = 500; $img = imagecreate ...