c / c ++ fwrite或fprintf如何工作。冲洗或fclose后会发生什么 [英] how does c/c++ fwrite or fprintf works. what will happed after flush or fclose

查看:175
本文介绍了c / c ++ fwrite或fprintf如何工作。冲洗或fclose后会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我什么时候用c / c ++写文件,如何以及何时写入磁盘?

感谢您的关注。

I wonders when I "write" a file in c/c++, How and when does it write to disk ?
Thanks for your attention.

推荐答案

当你写入文件时,数据并不总是物理地写入磁盘,因为磁盘操作是缓冲缓存),为此表现。刷新保证已写入的部分数据已提交到磁盘。如果您的进程意外终止,则将保留已写入的文件部分。关闭文件时,将在关闭之前刷新数据。



也许这种解释过于简化了,但我认为,对于编写应用程序,它应该足以在实际考虑中加以考虑。有关详细信息,请参阅:

http://en.wikipedia.org/wiki / Cache_%28computing%29 [ ^ ],

http://en.wikipedia.org/wiki/Disk_buffer [< a href =http://en.wikipedia.org/wiki/Disk_buffertarget =_ blanktitle =New Window> ^ ]。



-SA
When you write to the file, data is not always physically written to the disk, as the disk operation is buffered (cached), for the sake of performance. Flushing guarantees that already written part of data is committed to the disk. If your process gets terminated unexpectedly, the already written part of file will be preserved. When you close the file, the data is flushed before closing.

Maybe this explanation is overly simplified, but I think, for writing application, it should be enough to take into account in practical consideration. For more detail, please see:
http://en.wikipedia.org/wiki/Cache_%28computing%29[^],
http://en.wikipedia.org/wiki/Disk_buffer[^].

—SA


这篇关于c / c ++ fwrite或fprintf如何工作。冲洗或fclose后会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆