I'm trying compare the performance of a windows program when the disk cache is in its best state (when all files needed for the program to run are in memory cache, I just run it multiple times to get this state), and when the cache is in its worst state, that is completely empty.
The only way way I know to ensure that the cache is completely empty is by rebooting the computer, but this is not ideal since its takes too much time. Is there any way to do this without rebooting? I tried sync, but it does not invalidate the read cache...
In your call to
CreateFile
, include theFILE_FLAG_NO_BUFFERING
flag. See the CreateFile reference page at MSDN for more information. Note in particular the requirements.If it's too much effort to modify your code to do this, try writing a simple utility program to read a file that is larger than physical memory. This may be enough to flush the files you care about from the filesystem cache.