但是,是否有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中的所有文件缓冲区?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)