UNIX 缓冲 I/O 与无缓冲 I/O

发布于 2024-12-20 01:08:09 字数 130 浏览 4 评论 0原文

无缓冲 I/O 和标准 I/O 有什么区别?我知道使用read()、write()、close()都是无缓冲IO。 printf和gets都是缓冲IO。我也知道对于大事务使用缓冲IO会更好。我只是不知道原因。在这种情况下,术语“缓冲”是什么意思?

What is the difference between Unbuffered I/O and standard I/O? I know that using read(), write(), close() are unbuffered IO. Printf and gets are buffered IO. I also know that it is better to use buffered IO for big transactions. I just dont know the reason why. And what does the term "buffered" mean in this context?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荭秂 2024-12-27 01:08:09

无缓冲 I/O 只是意味着在读取或写入时不使用任何缓冲区。通常,当我们使用 read() 和 write() 等系统调用时,它们会逐个字符地读取和写入,并可能导致性能大幅下降。因此,对于大数据,通常首选高级读/写或简单的缓冲 I/O。缓冲仅仅意味着我们处理的不是单个字符而是一个字符块,这就是为什么有时它也称为块 I/O。通常在 Unix 中,当我们使用高级读/写函数时,它们会获取/存储给定块大小的数据,并将它们放入缓冲区高速缓存中,这些 I/O 函数从该缓冲区高速缓存中获取所需的数据量。

Unbuffered I/O simply means that don't use any buffer while reading or writing.Generally when we use System calls like read() and write() they read and write char by char and can cause huge performance degradation . So for huge date generally high level reads/writes or simply buffered I/O are preferred .Buffered simply means that we are not dealing with single char but a block of chars, that is why sometimes it also known as block I/O.Generally in Unix when we use high level read/write functions they fetch/store the data of a given block size and place them in buffer cache and from this buffer cache these I/O functions get the desired amount of data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文