C++ FILE without writing to disk
Beside the already mentioned GNU's fmemopen()
, which is known in POSIX as open_memstream, similar solution can be obtained combining mmap()
(using MAP_ANONYMOUS) or any other OS-specific function that returns a file descriptor to a block of memory, and fdopen()
.
EDIT: that was wrong, mmap doesn't create a file descriptor.
The GNU libc has, e.g., fmemopen
which will give you a FILE *
that writes to memory. Try man fmemopen
on your Linux system for details.
I suspect (but do not know for sure) that fmemopen
is a wrapper that orchestrates the mmap
/fdopen
approach mentioned by @Cubbi.
If you are on Mac OS X or iOS you don't have access to fmemopen. I've open sourced a solution here:
http://jverkoey.github.com/fmemopen/