[英]Can I create a memory-mapped FILE * in C/Objective-C on iOS?
I have a library which consumes a FILE *
and outputs data to another FILE *
. 我有一个库,它使用FILE *
并将数据输出到另一个FILE *
。
I want to handle both the input to this library and the output from this library in memory without reading/writing to/from a file on the disk. 我想处理这个库的输入和内存中该库的输出,而无需读取/写入磁盘上的文件。
We're doing this in iOS - so running the library as a separate app and using stdin
/ stdout
isn't (as far as I know) a viable option. 我们在iOS中这样做 - 所以运行库作为一个单独的应用程序并使用stdin
/ stdout
不是(据我所知)一个可行的选项。
Because ObjC is a superset of C, all you have to do is #import/#include <stdio.h>
to gain access to the funopen()
which in itself contains the functions readfn
, writefn
, seekfn
, and closefn
. 因为ObjC是C的超集,所以你要做的就是funopen()
#import/#include <stdio.h>
来访问funopen()
,它本身包含readfn
, writefn
, seekfn
和closefn
。 And fwopen which has an example showing how to write to two streams at this other SO question . 并且fwopen有一个例子显示如何在另一个SO问题上写入两个流。
Mac OSX and iOS don't include
fmemopen
and
open_memstream
because they are apparently
unportable linux functions
Mac OSX和iOS不包括
fmemopen
和
open_memstream
因为它们显然是不可
移植的linux函数
As of macos 10.13, ios 11.0, tvos 11.0, and watchos 4.0, fmemopen
and open_memstream
along with a few other helpful POSIX.1-2008 standard functions are available in stdio. 从maco 10.13,ios 11.0,tvos 11.0和watchos 4.0, fmemopen
和open_memstream
以及一些其他有用的POSIX.1-2008标准函数可以在stdio中获得。
Have a look at https://github.com/shyuep/pyhull/tree/master/src/fmemopen , I've tested it myself on a Mac OSX 10.8.2 and it is working ok. 看看https://github.com/shyuep/pyhull/tree/master/src/fmemopen ,我已经在Mac OSX 10.8.2上自己测试了它,它运行正常。
Author states it should also work on iOS. 作者声明它也应该适用于iOS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.