What's the most efficient inter-process communication method for a high-bandwidth data stream on a Mac?
c++, ipc, macos
Solution
You certainly can't beat shared memory if you can manage the synchronization. Single copy in memory, no other movement. Your only "slow" point will be any fighting over who can do what, and where.
Problem
I have a C++ program (running under MacOS/X) that generates a high-bandwidth stream of data (about 27 megabytes per second). A second C++ program receives that data and processes it in (soft) real time. Low latency and high reliability are both goals for this system. Due to circumstances beyond my control, the two processes need to be kept separate -- that is, I can't convert them into two threads within the same process. Currently I'm using UDP packets (sent by process A to a UDP port on 127.0.0.1 that process B is listening on) to implement this data transfer, and that more-or-less-kind-of-works (modulo the occasional dropped packet), but I'm wondering if there isn't a more efficient/appropriate mechanism for this use case. Would a Unix pipe() be significantly more efficient or reliable? Or should I write the data to a mmap()'d shared memory region, and use a pipe/socket/semaphore/etc to synchronize the two processes' writes and reads? Or is UDP-over-the-loopback-device already efficient enough that there is little benefit to be gained by switching over to another method?