What is fadvise/madvise equivalent on windows?

别等时光非礼了梦想. 提交于 2019-11-27 06:04:41

问题


On UNIX, I can, for example, tell the OS that the mapping will be needed in the future with posix_fadvise(POSIX_FADV_WILLNEED). It will then read-ahead the data if it feels so.

How to tell the access intend to Windows ?


回答1:


Actually, as Anders mostly suggested, there is no such method in the memory management functions available in Windows 7 and earlier.

2 different ways exists to do something similar :

  • Read the data asynchronously with ReadFileEx. The data might then still be in the file cache when needed later.
  • Open the file with a streaming hint with the FILE_FLAG_SEQUENTIAL_SCAN attribute of CreateFile. Readahead would then perhaps be automatically done.



回答2:


Beginning with Windows 8, there is the PrefetchVirtualMemory function for this purpose.




回答3:


You can pass FILE_FLAG_RANDOM_ACCESS or FILE_FLAG_SEQUENTIAL_SCAN to CreateFile()



来源:https://stackoverflow.com/questions/1201168/what-is-fadvise-madvise-equivalent-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!