communicating between processes with shared-memory results zero-copy? communicating between processes with shared-memory results zero-copy? linux linux

communicating between processes with shared-memory results zero-copy?


Shared memory in general is designed specifically to not cause copy overhead (source: http://www.boost.org/doc/libs/1_46_0/doc/html/interprocess/sharedmemorybetweenprocesses.html#interprocess.sharedmemorybetweenprocesses.sharedmemory.shared_memory_what_is).

If you're using C++, Boost::Interprocess is a great library for implementing what you're describing in a cross-platform way -- you can use their shared memory class combined with a named_upgradable_mutex. The named_upgradable_mutex class has support for giving exclusive and sharable locks on a resource, so you can easily implement your consumer-producer model with it. (source: http://www.boost.org/doc/libs/1_37_0/doc/html/boost/interprocess/named_upgradable_mutex.html#id2913393-bb )


Shared-memory should not introduce any copies (cache coherency excepted), and you can directly access the memory so you may be able to avoid copies in your code.


Yes it should be zero-copy.

However, it's also a (possibly premature) optimisation and you need to take considerable care to ensure that your processes cooperate properly with allocation / deallocation / modifying of shared memory. You'd certainly need some kind of mutex to avoid concurrent access problems.

Personally I'd use pipes until performance becomes a proper issue. If it really does, the suggestion to use Boost::Interprocess or similar library, is a reasonable one.