How to process RAM data as if it were a real file?

So, I have temporary data in my program (in RAM). I want to somehow show that this is a file (for example, to send it to another program that takes a file link as an argument)?

Is it possible?

How to do it?

+6
c ++ c windows ram share
source share
5 answers

You can do this in C using the popen() function:

 FILE *f = popen("program args", "w"); // write your output to f here using stdio pclose(f); 

This is possible if your external program reads its input from stdin .

+1
source share

Why not just burn the file to disk? If writing to disk is too slow, you can pass the FILE_ATTRIBUTE_TEMPORARY flag to CreateFile to save the data in the cache (and not write it to the physical device).

Sometimes obvious solutions are the best ...

+15
source share

If you support your operating system (Unixoid and Windows systems), you can try to use memory mapped files .

+11
source share

You can use pipe ()

  The pipe () function shall create a pipe and place two file descriptors,
 one each into the arguments fildes [0] and fildes [1], that refer to the
 open file descriptions for the read and write ends of the pipe.  Their
 integer values ​​shall be the two lowest available at the time of the
 pipe () call.  The O_NONBLOCK and FD_CLOEXEC flags shall be clear on both
 file descriptors.  (The fcntl () function can be used to set both these
 flags.)
0
source share

Yes it is possible. You can transfer your data to another application through the interprocess communication mechanism:

  • Depending on your OS, you have different options. You could create a channel, as other posters mentioned here, as many operating systems have channels.
  • You can also use shared memory.
  • You can simply write it to a file and then open that file in your other application.
  • Many operating systems have other methods that you can use.

EDIT: MSDN lists all the IPC mechanisms available for Windows here .

0
source share

All Articles