Inter Process Communication – Pros and Cons of Sockets vs Shared Memory

debugginglanguage-agnosticmemoryprocesssockets

I understand that two of the many more options for inter process communication can be :

  1. Shared memory
  2. Sockets

Actually I saw these two options being exposed by Intellij Idea for debugging a Java application . I want to know what are the pros and cons of each approach .

Best Answer

A few advantages for each off the top of my head. Note that some of these items may not apply in all cases; these are just general observations.

Sockets

Simple and controlled. Can be extended to network sockets as necessary with little or no modification. Programming model requires serialization, which in turn requires you to think about what data actually gets transferred from A to B. Synchronization is necessarily built-in to the communication mechanism; no other synchronization necessary.

Shared Memory

Does not necessarily require a syscall (therefore potentially faster). Sharing does not explicitly require data to be transferred -- data can be made available that the recipient does not retrieve (bandwidth does not have to be wasted transferring data that the recipient won't use). No serialization/deserialization step means no time spent on communication overhead.

Related Topic