题
因此,我的程序(在RAM)中有一些临时数据。我想以某种方式使它看起来像一个文件(例如,将其发送到将文件链接作为参数的另一个程序中发送)?
可能吗?
如何做这样的事情?
解决方案
您可以在C中使用 popen()
功能:
FILE *f = popen("program args", "w");
// write your output to f here using stdio
pclose(f);
如果您的外部程序从中读取其输入,这是可能的 stdin
.
其他提示
为什么不简单地将文件写入磁盘?如果写入磁盘太慢,您可以通过 FILE_ATTRIBUTE_TEMPORARY
标记为 CreateFile 将数据保存在缓存中(并避免将其写入物理设备)。
有时明显的解决方案是最好的...
如果您的操作系统(Unixoid Systems和Windows Do)支持,您可以尝试使用 内存映射文件.
您可以使用管道()
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.)
不隶属于 StackOverflow