setbuf、setvbuf

setbuf, setbuffer, setlinebuf, setvbuf - stream buffering operations

用于更改buffering
这些调用必须在fopen流之后,操作这些stream流之前调用。

#include <stdio.h>

void setbuf(FILE *stream, char *buf);
int setvbuf(FILE *stream, char *buf, int mode, size_t size);
//Returns: 0 if OK, nonzero on error

void setbuffer(FILE *stream, char *buf, size_t size);
void setlinebuf(FILE *stream);   
setbuf

开启buffering,``buf所代指的buffer大小必须为BUFSIZ(定义在stdio.h),一般是fully buffered,一些系统在与终端设备关联的时候,采用的是行缓冲
关闭bufferingbufNULL即可

setvbuf

使用mode来指定想要的类型

mode
_IOFBFfully buffered
_IOLBFline buffered
_IONBFunbuffered

If we specify an unbuffered stream, the buf and size arguments are ignored.

If we specify fully buffered or line buffered, buf and size can optionally specify a buffer and its size.

If the stream is buffered andbuf is NULL, the standard I/O library will automatically allocate its own buffer of the appropriate size for the stream. By appropriate size, we mean the value specified by the constant BUFSIZ.

一些C库如GNU C库,使用stat structure的st_blksize来决定合适的标准IObuffer尺寸。

figure 5.1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猎羽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值