2

Is there a method in Windows to clear the whole disk cache? I am doing benchmarks on a disk and try to measure which of my methods has the best performance in C#. The problem is though that the disk caching in Windows prevents me from from getting correct results.

So the question is if there is a method to remove all cached files from the Windows disk cache?

RamMap from SysInternals is able to do it, so there must be a way, but I couldn't find how to do it.

dymanoid
  • 14,771
  • 4
  • 36
  • 64
msedi
  • 1,437
  • 15
  • 25
  • 1
    you can try to run cmd commands to do it – Omri Attiya Aug 28 '20 at 11:42
  • Have a look at this [related post](https://stackoverflow.com/questions/18593906/linux-sync-equivalent-windows-api) from 2013. – Axel Kemper Aug 28 '20 at 11:54
  • @AxelKemper: I'm not sure if FlushFileBuffer really remove the cache from the windows memory manager. RamMap example tells me that the file is still mapped. Also FLushFileBuffers is (at least I though) only to force a writethrough, right? My files are open in readonly mode, nothing is written. – msedi Aug 28 '20 at 11:59
  • 1
    This [answer](https://stackoverflow.com/a/7701908/2557128) seems like what you want, though it is probably depending on undocumented operation. – NetMage Aug 28 '20 at 19:49
  • @NetMage: Thx a lot. I will try this one. – msedi Sep 10 '20 at 08:08

0 Answers0