c – 如何刷新Windows中的所有文件缓冲区?

c – 如何刷新Windows中的所有文件缓冲区?,第1张

概述Windows中有FlushFileBuffers()API可以将缓冲区刷新到单个文件的硬盘驱动器. Linux中有sync()API来刷新所有文件的文件缓冲区. 但是,是否有WinAPI用于刷新所有文件,即sync()模拟? https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-flushfilebuffe Windows中有Flushfilebuffers()API可以将缓冲区刷新到单个文件的硬盘驱动器. Linux中有sync()API来刷新所有文件的文件缓冲区.

但是,是否有WinAPI用于刷新所有文件,即sync()模拟?

解决方法 https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-flushfilebuffers

可以冲洗整个硬盘驱动器.

To flush all open files on a volume,call Flushfilebuffers with a handle to the volume. The caller must have administrative privileges. For more information,see Running with Special Privileges.

此外,如果由于某种原因必须刷新数据,同一篇文章规定了要遵循的正确过程:使用file_FLAG_NO_BUFFERING和file_FLAG_WRITE_THROUGH标志的Createfile函数.

Due to disk caching interactions within the system,the Flushfilebuffers function can be inefficIEnt when used after every write to a disk drive device when many writes are being performed separately. If an application is performing multiple writes to disk and also needs to ensure critical data is written to persistent media,the application should use unbuffered I/O instead of frequently calling Flushfilebuffers. To open a file for unbuffered I/O,call the Createfile function with the file_FLAG_NO_BUFFERING and file_FLAG_WRITE_THROUGH flags. This prevents the file contents from being cached and flushes the Metadata to disk with each write. For more information,see Createfile.

但是还要检查file buffering关于内存和数据对齐的限制.

总结

以上是内存溢出为你收集整理的c – 如何刷新Windows中的所有文件缓冲区?全部内容,希望文章能够帮你解决c – 如何刷新Windows中的所有文件缓冲区?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1212266.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存