-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How about using shared-memory to implement ipc-channel. #128
Comments
Well, for one, As for using shared memory for IPC in general, that's quite a different story: it's one of these things that actually start looking much less attractive when you consider the details :-) Specifically -- aside perhaps from narrow use cases that can work with lockless data structures -- doing IPC over shared memory still requires issuing system calls, to do synchronisation. For small messages at least, the system calls totally dominate performance -- so if we need to do system calls anyway, we can just as well transfer the actual data directly with them, which is likely to offer better performance. (Since the IPC paths are generally well optimised at the OS level.) Even for medium-sized messages, using the system mechanisms is probably cheaper. Shared memory might seem attractive, because in theory, you could avoid copying the actual data. That however would require setting up shared memory buffers for every message we want to transfer -- adding extra overhead, which will usually outweigh the saved copy. (Copying memory is in fact a relatively cheap operation, which is pretty hard to beat.) Plus it would make the API more tricky to use. See #126 for some relevant discussion. Having said all that, I did actually recently ponder the possibility of using a shared memory based mechanism, to improve portability and consistency: the basic mechanism could be the same on all platforms; and porting would boil down to plugging in system-specific primitives for managing shared memory regions and for inter-process locking/synchronisation... |
Another important issue is that Note that this happens a lot when using a communication style based on remote procedure calls, where every request message carries a distinct channel for the reply. It might be argued that this is not the optimal approach I guess -- but doing otherwise would entail radically different usage patterns... |
FYI, memfd was designed as a safe shared-memory mechanism for Linux. It can be used to share raw data with another process thanks to a file descriptor (which is needed to send IPC channels endpoints over IPC channel). Moreover, memfd support memory sealing which is needed when dealing with untrusted peer (as explained in the man page). |
Also see #125. |
Refer to http://doc.qt.io/qt-5/qtcore-ipc-sharedmemory-example.html
The text was updated successfully, but these errors were encountered: