问题描述
在字符串流上阅读GNU文档时>我发现有两个功能相似的功能:
While reading through the GNU documentation on string streams I found two similar functions that do very similar things:
FILE * fmemopen (void *buf, size_t size, const char *opentype)
FILE * open_memstream (char **ptr, size_t *sizeloc)
通过阅读文档,似乎应该使用open_memstream
来打开输出流,使用fmemopen
来输入.吸引我的是可以传递给fmemopen
的opentype
参数.
From reading the documentation, it seems open_memstream
should be used for opening an output stream and fmemopen
for input. What catches me is the opentype
argument that you can pass to fmemopen
.
Linux 联机帮助页说明:
那么,如果fmemopen
可以处理打开输入/输出流的话,使用open_memstream
有什么意义呢?
So what would be the point of using open_memstream
if fmemopen
can handle opening an input/output stream?
推荐答案
对于fmemopen
,缓冲区是在打开时或之前分配的,以后不会更改大小.如果要编写它,则必须在开始之前知道输出的大小.使用open_memstream
,缓冲区随着您的写入而增长.
With fmemopen
, the buffer is allocated at or before the open, and doesn't change size later. If you're going to write to it, you have to know how big your output will be before you start. With open_memstream
the buffer grows as you write.
这篇关于fmemopen和open_memstream有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!