Fastest IPC method on Windows 7

30,606

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

Share:
30,606
Cartesius00
Author by

Cartesius00

Fun

Updated on July 10, 2022

Comments

  • Cartesius00
    Cartesius00 almost 2 years

    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?

  • Max Barraclough
    Max Barraclough about 4 years
    stackoverflow.com/q/5140312 raises some concerns about Boost.Interprocess on Windows. Do you know if it's true that it may fail to delete a file if a process crashes?
  • Matteo Italia
    Matteo Italia about 4 years
    From what I gather they essentially implemented a cross-process mutex in the same way as you would do on POSIX, i.e. with a file, sharing with it the classic problem of "program crashes, lock remains in place" (plus the implementation seems sloppy in general). Anyhow, this isn't related to the file memory mapping thing at all, which I think can be used without problems.