在C ++中建立IPC机制的最简单方法 [英] Simplest way to establish an IPC mechanism in C++

查看:84
本文介绍了在C ++中建立IPC机制的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux中用于本地主机的不同类型的IPC机制之间,在C ++中数据交换速度和代码简单性方面最有效的方法是什么?



是吗D-Bus或UDP套接字或其他机制,即Sys-v,信号或管道?为什么?

解决方案

使用IPC,确实没有最佳选项。他们都有积极和消极的方面。



例如,最快可能就像共享内存一样,但在单个系统框架之外并不是那么实用,任何解决方案也不太可能交叉-平台。使用套接字,两个(或更多)部件的位置或主机操作系统无关紧要,但操作系统会进行一些开销处理,因此它自然会慢一些(相比之下)。



即使在每种IPC类型中,也有不同的子类型具有优点/缺点。例如,您提到了UDP。嗯,UDP将比TCP快,但不保证交付(或交付顺序)。因此,如果你必须交付每个数据包,UDP有点不切实际。您可以在应用程序层构建一个检查系统,但此时您开始复制TCP。



使用共享数据的系统的一个示例是虚拟模拟器。它们必须尽可能接近实时工作,否则体验将会滞后,因此他们必须使用最快的IPC,而流式音乐可以通过TCP / IP获得,因为音乐的采样率通常可以低到足够低与TCP / IP的所有有益保证一起传输。另一方面,许多视频电话会议都是通过UDP完成的,因为只要大多数人使用UDP就不会丢弃一两个数据包。



总而言之,查看您的应用程序并定义您的系统最优先级以及您可以不用的内容,然后查看您的IPC选项并查看最接近您需要的内容。


< blockquote>根据定义,比较尝试是不正确的。什么是最有效,你会如何定义它?比方说,发送信号并处理它可能是最快的,但通过套接字你可以发送和接收一些数据...



-SA

Between different types of IPC mechanisms in Linux for local host, what's the most efficient way in terms of data exchange speed and code simplicity in C++?

Is it D-Bus or UDP sockets or other mechanisms i.e. Sys-v, signals or pipes? And why?

解决方案

With IPC, there really is no "best" option. They all have positive and negative aspects.

For example, fastest would probably be something like shared memory, but it's not all that practical outside of a single system framework and any solution is also not likely to be cross-platform. Using sockets, it doesn't matter where the two (or more) pieces are located or the host OS, but there will be some overhead processing that's done by the OS, so it's naturally slower (by comparison).

Even within each IPC type, there's different subtypes that will have pros/cons. For example, you mentioned UDP. Well, UDP will be faster than TCP but has no guarantee of delivery (or order of delivery). So if you MUST have each packet delivered, UDP is a bit impractical. You could build a check system in at the application layer, but at that point you start to replicate TCP.

One example of systems that use shared data are virtual simulators. They must work as close to real-time as possible, otherwise the experience will lag, so they have to use the fastest IPC available, whereas streaming music can get away with TCP/IP, because the sampling rates of music can usually be low enough to be transmitted with all the beneficial guarantees of TCP/IP. On the other hand, a lot of video teleconferencing is done with UDP, because they don't care if a packet or two are dropped as long as most make it.

To summarize, look at your application and define what are your system top priorities and what are things you can live without, then look at your IPC options and see what fits closest to what you need.


The attempt of comparison would be incorrect by definition. What is "most efficient", how would you define it? Say, sending the signal and handling it would probably be the fastest, but through the sockets you can send and receive some data…

—SA


这篇关于在C ++中建立IPC机制的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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