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 the FILE_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.
About writing a utility that reads a huge file, how am I garanteed that it will empty the cache? Maybe windows manages its cache in a way that it will not cache all of the huge file, and keep some space for more files. Or maybe not... actually I have no idea. Anyways, I'll give it a try and see the results - Nicolas Rousseau-Dupuis 2009-06-16 15:48