内存流

内存流

原型

  • 字符串流的形式,识别的null
// 追加形式也是找到第一个null,如果没有找到则在最后一个字符上
FILE *fmemopen(void *buf, size_t size, const char *mode);
  • 面向字节的,只能写打开,不能指定缓冲区,通过ptr确定位置和大小sizeloc,需要自行释放,添加字节会增加流的大小
#include <stdio.h>
FILE *open_memstream(char **ptr, size_t *sizeloc);
// 宽字节
#include <wchar.h>
FILE *open_wmemstream(wchar_t **ptr, size_t *sizeloc);

mark

Initially, the buffer has a size of zero. After closing the stream, the caller should free(3) this buffer.

初始化的时候大小是0,其实也就是说这个地址和大小应该在fclose或者fflush后使用,下次再用的时候就变了.

close后内存依然没有释放,所以需要手动释放

posted @ 2019-11-29 21:09  zongzi10010  阅读(186)  评论(0编辑  收藏  举报