C++进程间通信的最佳方式 [英] Best way for interprocess communication in C++

查看:35
本文介绍了C++进程间通信的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个进程,一个会查询另一个数据.在有限的时间内(每秒 10000 次)会有大量查询,并且每秒将传输数据(>100 mb).数据类型将是一个整体类型(双,整数)我的问题是用什么方式连接这个过程?

I have two processes one will query other for data.There will be huge amount of queries in a limited time (10000 per second) and data (>100 mb) will be transferred per second.Type of data will be an integral type(double,int) My question is in which way to connect this process?

共享内存、消息队列、lpc(本地过程调用)或其他....

Shared memory , message queue , lpc(Local Procedure call) or others....

我还想问你推荐哪个图书馆?顺便说一下,请不要建议 MPI.在 windows xp 32 位下

And also i want to ask which library you suggest? by the way please do not suggest MPI. edit : under windows xp 32 bit

推荐答案

One Word: Boost.InterProcess.如果真的需要快速,共享内存是最佳选择.由于操作系统在虚拟地址和物理地址之间进行通常的映射,并且不需要数据副本,因此您的开销几乎为零.您只需要注意并发问题.

One Word: Boost.InterProcess. If it really needs to be fast, shared memory is the way to go. You nearly have zero overhead as the operation system does the usual mapping between virtual and physical addresses and no copy is required for the data. You just have to lookout for concurrency issues.

对于像 shutdownquery 这样的实际发送命令,我会使用消息队列.在我了解 boost 之前,我以前使用 localhost 网络编程来做到这一点,并使用手动共享内存分配.该死的,如果我需要重写应用程序,我会立即选择 boost.Boost.InterProcess 使这对您来说更容易.看看吧.

For actually sending commands like shutdown and query, I would use message queues. I previously used localhost network programming to do that, and used manual shared memory allocation, before i knew about boost. Damn if i would need to rewrite the app, I would immediately pick boost. Boost.InterProcess makes this more easy for you. Check it out.

这篇关于C++进程间通信的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆