Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest IPC method on 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).

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

like image 973
Cartesius00 Avatar asked Aug 19 '11 20:08

Cartesius00


People also ask

Is IPC faster than shared memory?

Fastest IPC mechanism in OS is Shared Memory. Shared memory is faster because the data is not copied from one address space to another, memory allocation is done only once, andsyncronisation is up to the processes sharing the memory.

Which IPC mechanism is faster?

Shared memory is the fastest form of interprocess communication. The main advantage of shared memory is that the copying of message data is eliminated.

What are different IPC techniques?

Different ways of IPC are pipe, message passing, message queue, shared memory, direct communication, indirect communication and FIFO.

What is Windows IPC?

The Windows operating system provides mechanisms for facilitating communications and data sharing between applications. Collectively, the activities enabled by these mechanisms are called interprocess communications (IPC). Some forms of IPC facilitate the division of labor among several specialized processes.


1 Answers

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.

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.

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.

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

like image 93
Matteo Italia Avatar answered Sep 18 '22 15:09

Matteo Italia