Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing data locally (like with sockets) between multiple programs in C++

My goal is to send/share data between multiple programs. These are the options I thought of:

  • I could use a file, but prefer to use my RAM because it's generally faster.
  • I could use a socket, but that would require a lot of address information which is unnecessary for local stuff. And ports too.
  • I could ask others about an efficient way to do this.

I chose the last one.

So, what would be an efficient way to send data from one program to another? It might use a buffer, for example, and write bytes to it and wait for the reciever to mark the first byte as 'read' (basically anything else than the byte written), then write again, but where would I put the buffer and how would I make it accessible for both programs? Or perhaps something else might work too?

I use linux.

like image 366
RPFeltz Avatar asked Dec 20 '11 12:12

RPFeltz


2 Answers

What about fifos and pipes? if you are on a linux environment, this is the way to allow 2 programs to share data.

like image 170
Francesco Belladonna Avatar answered Nov 14 '22 22:11

Francesco Belladonna


The fastest IPC for processes running on same host is a shared memory.

In short, several processes can access same memory segment.

See this tutorial.

like image 33
Michał Šrajer Avatar answered Nov 14 '22 23:11

Michał Šrajer