question

MillmanMark-9504 avatar image
0 Votes"
MillmanMark-9504 asked YujianYao-MSFT commented

Clear file from memory cache

I'm developing in C++ and C# and working with larger files (tens to hundreds of GB) and performance is a major issue. However, once a file has been read it is cached in memory and subsequent reads no longer go to disk. This makes it difficult to gauge the performance. For example, in the program I'm currently working on a run immediately after a reboot takes 92 seconds. Re-running the program (and until I change input files or reboot again) it only takes 7 seconds.

I've used RamMap and this helps but it doesn't appear to let me clear individual files and if I Empty everything then my timings are off because everything in the system has to be reloaded.

Is there any way C++ or C# function to tell Windows to clear cached files out of memory using a file naming mask?

Thanks, Mark

dotnet-csharpc++windows-sysinternals-procmon
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YujianYao-MSFT avatar image
0 Votes"
YujianYao-MSFT answered YujianYao-MSFT commented

Hi,

When opening or creating a file with the CreateFile function, the FILE_FLAG_NO_BUFFERING flag can be specified to disable system caching of data being read from or written to the file.

The function of FILE_FLAG_WRITE_THROUGH is write operations will not go through any intermediate cache, they will go directly to disk.

You could use these two flags to bypass the cache when creating files, so as to avoid the inability to clear the cache of some files.

Please refer to the document for more details.

Best Regards,

Elya


If the response is helpful, please click "Accept Answer" and upvote it.


Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @MillmanMark-9504,

May I know if you have got any chance to check my answer? I am glad to help if you have any other questions.

0 Votes 0 ·