Sorry,I mean FILE *fp actrually.
There is a c function of a legacy system,which only accept FILE *fp
parameter and parse the content,and now the new system also provide
char* for the content,and I think saving char* to a file and opening it
to get FILE *fp then call the function is poor performance. so I doubt
is there any way to directly push char* into the stream without disk
reading and writing.
So you have a string, and you want to arrange for that string to be
read from a FILE*, but you're concerned that writing to and reading
from a disk file will be too slow.
There's nothing in the C standard that says a FILE* has to be
associated with a disk file. A file is just an external source of
data that can be opened given its name, and that behaves in certain
ways. The actual data can be stored on disk, in memory, or on clay
tablets as far as the C standard is concerned.
On some systems, you might have (or be able to create) a file or file
system that's actually stored in memory. <OT>It's not uncommon for
/tmp on Unix systems to be implemented with something called "swapfs";
see Google or your system's documentation for details.</OT>
Standard C provides the tmpfile() and tmpnam() functions. If your
system provides a file system that's not limited by disk speeds, it's
not unlikely that tmpfile() and tmpnam() will use it.
Implementations typically do buffering at various levels. If you
create a temporary file, write to it, use freopen() to re-open it in
input mode, you *might* be able to avoid writing the data to disk.
This is not guaranteed; in addition, C99 7.19.5.4, "The freopen
function", says
It is implementation-defined which changes of mode are permitted
(if any), and under what circumstances.
Your system might provide something that lets you associate a FILE*
with a string. Any such feature is, of course, non-portable.
<OT>
C++ provides something called "string-based streams", which act like
file streams but are associated with strings rather than external
files. If you have a C++ implementation, and if C++ provides a way to
associate a string-based stream with a C-style FILE* (I have no idea
whether it does), you might be able to interface with some C++ code to
do what you need. Obviously any questions about this approach (if
it's possible at all) belong in comp.lang.c++.
</OT>