Search code examples
c++boostboost-asioboost-interprocessinter-process-communicat

IPC through two different executables?


I have the following problem, and I understand that I need to use either IPC via shared memory or network sockets.

I have one executable (meaning a separate .exe), compiled with VS2010, that gets the data from somewhere, and it should make that data available to the second executable.

boost::interprocess::managed_shared_memory managed_shm(
    boost::interprocess::open_or_create,
    "MyMemBlock",
    4000000);

The second executable is compiled with VS2012 and should receive that data (or fetch from memory) and process it.

// fails with a boost::interprocess::interprocess_exception
boost::interprocess::managed_shared_memory managed_shm(
    boost::interprocess::open_only,
    "MyMemBlock");

The whole thing needs to be as fast as possible. Compiling both executables with the same Visual Studio version is not an option, one codebase compiles only with VS2010, the other one only with VS2012/2013.

However, my first try with boost::interprocess didn't work (the second process throws a boost::interprocess::interprocess_exception), and I don't fully understand how exactly the memory gets shared, or more precise, how the shared memory information gets communicated from one process to the other. How does the first exe populate the information of the shared memory block? Does it only work for multiple processes inside one executable? Not multiple .exe's? Does it have to be the same boost DLL that is used by both executables? Is my only option IPC via Sockets?


Solution

  • IPC works across two different executables. The two processes accessing the shared memory don't need to be compiled into the same executable. In fact, they can be compiled with different versions of visual studio and different boost DLL's. However, one has to use the same version of boost in both executables.

    Quite interestingly, what is also not working, is running one executable in release-build and the other one in debug-build. I guess they allocate memory in a completely different way and can't share it.