Windows 中的 msync 等效项
Windows 中的 msync [unix sys call] 相当于什么? 我正在寻找 C、C++ 空间中的 MSDN api。 有关 msync 的更多信息,请访问 http://opengroup.org/onlinepubs/007908799/ xsh/msync.html
what is the equivalent of msync [unix sys call] in windows? I am looking for MSDN api in c,C++ space.
More info on msync can be found at http://opengroup.org/onlinepubs/007908799/xsh/msync.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
FlushViewOfFile
查看 Python 2.6 mmapmodule.c 以获取使用中的 FlushViewOfFile 和 msync 的示例:
更新:
我认为您不会在 win32 映射文件 API 中找到完全同等的情况。 FlushViewOfFile API 没有同步风格(可能是因为缓存管理器的可能影响)。 如果需要精确控制数据何时写入磁盘,也许您可以在创建映射文件的句柄时将
FILE_FLAG_NO_BUFFERING
和FILE_FLAG_WRITE_THROUGH
标志与 CreateFile API 结合使用?FlushViewOfFile
Checkout the Python 2.6 mmapmodule.c for an example of FlushViewOfFile and msync in use:
UPDATE:
I don't think you are going to find complete parity in the win32 mapped file APIs. The FlushViewOfFile API doesn't have a synchronous flavor (probably because of the possible impact of the cache manager). If precise control over when data is written to disk is required perhaps you can use the
FILE_FLAG_NO_BUFFERING
andFILE_FLAG_WRITE_THROUGH
flags with the CreateFile API when you create the handle to your mapped file?用于刷新所有文件映射的 Windows 等效项是
对于刷新部分文件映射
这在 MSDN 这里
标记
FILE_FLAG_NO_BUFFERING
实际上对内存映射文件没有任何作用(描述此处),也甚至使用这些标志创建文件句柄,元数据文件可以被缓存而不是被刷新,所以如果你想完全确保所有数据(包括文件访问时间)都被保存,FlushFileBuffers对于IO和MM总是需要的。 此处描述了此行为PS 一些现实世界的示例:SQLite 使用 MM 文件几乎仅用于 阅读,因此当您将 MM 文件用于编写/更新您需要了解此场景的所有副作用
Windows equivalent for flushing all filemapping is
And for flushing part of filemapping
This is described in MSDN here
Flag
FILE_FLAG_NO_BUFFERING
actually do nothing for memory mapped files (described here), also even file handle is created with these flags, metadata of file can be cached and not flushed, so FlushFileBuffers is always required for IO and MM, if you want to be completely sure that all data (including file access time) is saved. This behavior is described hereP.S. Some real world example: SQLite use MM-files almost only for reading, so when you are using MM-files for write/update you need understand all side effects for this scenario
我怀疑 FlushViewOfFile 实际上是正确的。 当我阅读 msync 手册页时,我不会认为它是实际上刷新磁盘缓存(磁盘单元中的缓存,而不是主内存中的系统缓存)。
在磁盘堆栈完成写入之前,FlushViewOfFile 不会返回; 与 msync 文档一样,它没有提及磁盘缓存中发生的情况。 我们或许应该在文档中更清楚地说明这一点。
I suspect FlushViewOfFile actually is the right thing. When I read the man page for msync, I would not assume that it is actually flushing the disk cache (the cache in the disk unit, as opposed to the system cache in main memory).
FlushViewOfFile won't return until the disk stack has completed the writes; like the msync documentation, it says nothing about what happens in the disk cache. We should probably take a look at making that more clear in the documentation.