在Windows 7上最快的IPC方法 [英] Fastest IPC method on Windows 7

查看:922
本文介绍了在Windows 7上最快的IPC方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最快的进程间通信(IPC)在Windows 7的方法?我们想和大家分享只是一个内存块(双向)。

What is the fastest possible Interprocess Communication (IPC) method on Windows 7? We would like to share only a memory blocks (two-way).

这是 ReadProcessMemory 或其他什么东西?
我们想用普通的 C 但是,例如,什么是Boost库使用了IPC?

Is it ReadProcessMemory or something else? We would like to use plain C but, for example, what does Boost library use for IPC?

推荐答案

ReadProcessMemory 甚至不应该被列为IPC方法;是的,它可以作为这样的,但它存在主要是为了调试的目的(如果你检查它的引用,它的类别调试功能下),而且它肯定比真正共享内存,因为它的拷贝速度较慢的进程的内存插入指定的缓冲区,而真正的共享内存没有这方面的开销。

ReadProcessMemory shouldn't even be listed as an IPC method; yes, it can be used as such, but it exists mainly for debugging purposes (if you check its reference, it's under the category "Debugging functions"), and it's surely slower than "real" shared memory because it copies the memory of a process into the specified buffer, while real shared memory doesn't have this overhead.

的IPC方法,通过Windows支持的完整列表可的在MSDN ;不过,如果你只是希望共享一个内存块的两个应用程序,你应该创建一个名为内存映射文件(由分页文件支持)与的CreateFileMapping / MapViewOfFile ,这应该是最简单,最快速的方法。文件映射的细节上其描述页 MSDN上。

The full list of IPC methods supported by Windows is available on the MSDN; still, if you just have two applications that want to share a memory block, you should create a named memory-mapped file (backed by the paging file) with CreateFileMapping/MapViewOfFile, that should be the most straightforward and fastest method. The details of file mapping are described on its page on MSDN.

的<一个href=\"http://www.boost.org/doc/libs/1_47_0/doc/html/interprocess/sharedmemorybetweenprocesses.html#interprocess.sharedmemorybetweenprocesses.sharedmemory\"相对=nofollow>相关升压IPC类可以作为一个简单包装的共享内存的行为,据我所知它只是封装了相关的特定系统的API调用,但最终你得到的通常的指针共享内存块,因此操作应尽可能快地使用本机API。

The relevant Boost IPC classes can act as a thin wrapper around shared memory, AFAIK it only encapsulates the calls to the relevant system-specific APIs, but in the end you get the usual pointer to the shared memory block, so operation should be as fast as using the native APIs.

由于这个原因,我建议你使用 Boost.Interprocess中,因为它是可移植的,C ++ - 友好(它提供了RAII语义)和共享内存块已经被创建后不给你任何性能损失(它的可以的提供共享内存的附加功能,但他们都选择在 - 如果你只是想共享内存,你得到的只是它)

Because of this I advise you to use Boost.Interprocess, since it's portable, C++-friendly (it provides RAII semantics) and does not give you any performance penalty after the shared memory block has been created (it can provide additional functionalities on shared memory, but they are all opt-in - if you just want shared memory you get just it).

这篇关于在Windows 7上最快的IPC方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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