问题
I use a file to communicate between Python and Ruby script. But, we have mmap. So here are my questions.
- Can I do the same thing (communicate between processes) with mmap?
- What advantage can mmap give us over physical file? Speedup?
- What would be the easiest way to communicate between two processes?
- What would be the fastest way to communicate between two processes?
回答1:
one advantage of mmap over physical file is indeed speedup, but anything is going to be faster than a physical file !
the easiest way to communicate between to processes is either a pipe or a socket. they are easier because they are streams, so they do not impose a limit on the length of the data you can exchange between the processes, contrary to a file or a mmap which have bounds.
回答2:
It might depend on what you want to communicate. If you are just giveing a massive data set from one app to the other then mmap files might make sense. If you have messages then some sort of IPC/RPC protocol may be better. If you are streaming data from one app to the other pipes/sockets might be better.
With mmaps you still have to manage them as a file and so you have to open and close them in a way that will synchronise. This may affect performance, and so you may want to use streams/pipes.
来源:https://stackoverflow.com/questions/2738564/is-mmap-the-best-way-to-communicate-between-processes