41

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?

asked Aug 19, 2011 at 20:48

1 Answer 1

50

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

answered Aug 19, 2011 at 20:56
Sign up to request clarification or add additional context in comments.

2 Comments

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.