Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create a memory-mapped FILE * in C/Objective-C on iOS?

Tags:

c

ios

objective-c

I have a library which consumes a FILE * and outputs data to another 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.

like image 260
Steve Avatar asked Apr 20 '12 19:04

Steve


2 Answers

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. And fwopen which has an example showing how to write to two streams at this other SO question.

Mac OSX and iOS don't include fmemopen and open_memstreambecause they are apparently unportable linux functions

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.

like image 180
CodaFi Avatar answered Sep 22 '22 08:09

CodaFi


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.

Author states it should also work on iOS.

like image 35
fernandospr Avatar answered Sep 24 '22 08:09

fernandospr