13

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 ?

Steve Schnepp
  • 4,620
  • 5
  • 39
  • 54

3 Answers3

13

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

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
11

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.
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
Steve Schnepp
  • 4,620
  • 5
  • 39
  • 54
5

You can pass FILE_FLAG_RANDOM_ACCESS or FILE_FLAG_SEQUENTIAL_SCAN to CreateFile()

Anders
  • 97,548
  • 12
  • 110
  • 164
  • Are that the only hinting possibilities on Windows ? – Steve Schnepp Jul 30 '09 at 06:46
  • 1
    As far as hints go, I think so. You can disable caching and things like that, but some of those other flags have alignment requirements so its more than a simple hint – Anders Jul 30 '09 at 09:57
  • 1
    FILE_ATTRIBUTE_TEMPORARY looks useful too - according to http://msdn.microsoft.com/en-us/library/aa363858%28v=vs.85%29.aspx#caching_behavior it tells the system to avoid writing the data to disk if there's enough cache memory available. – BCran Jan 03 '11 at 22:33