Question

I have two C++ programs P1 and P2 (each making an executable file). P1 saves a string in a file and P2 loads the string and uses it. This process is just for exchanging data between these two separate programs.

Is it possible to save the string somewhere in RAM instead, so that Hard Disk will not be engaged?

Was it helpful?

Solution

Is it possible to save the string somewhere in RAM instead, so that Hard Disk will not be engaged?

Yes, you can use one of a few interprocess communication methods. The choices includes

  • sockets
  • a memory mapped file
  • shared memory
  • pipes

Here is an example of using a file mapped to RAM with a call to mmap.

A file mapped to RAM that can be modified by changing memory addresses directly instead of outputting to a stream, shares same benefits as a standard file.

Reading from and writing to a memory-mapped file avoids the extraneous copy that occurs when using the read( ) or write( ) system calls, where the data must be copied to and from a user-space buffer.

tutorial

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top