I am writing a network daemon, on Linux with kernel 2.6, which has one producer process and N of consumer processes, which does not make any change on the data, and does not create any response back to the producer.
Whenever the producer process produces a data object, of which the length varies from few 10 bytes to few 10 K-bytes, it has to pass the data object into one available consumer process.
First time, I considered to use a named/unnamed PIPE. However, they would be memory-copy overhead.
- producer's user-space buffer --copy--> kernel-space PIPE buffer
- kernel-space PIPE buffer --copy--> consumer's user-space buffer
Since the program may work with a large-number of peers with low latency, the copy-overhead could be harmful. Thus, I decided to use POSIX shared-memory with mmap().
I am just wondering if sharing data between processes using POSIX shared-memory with mmap() does not result any memory-copy, unlike PIPE.
Also, is there any other way to share data between processes, but results zero-copy? The program will be run on Linux with a recent version of kernel and may not have to have a cross-platform ability.
I decided not to spawn/run a thread for each consumer/produce, but a process due to design issues.
Thanks for reply.