简体   繁体   中英

Windows cache usage increases for files creation program written in C

I have a small test program that creates millions of files (for testing purposes) in thousands of folders. It is C code with fopen and fclose calls.

This code runs fine on Linux ( RHEL , SUSE ), but on Windows the memory usage increases as the number of files to create increases (near a million files). The system memory usage increases to nearly 8 GB (system capacity) and the program becomes extremely slow (I assume due to swapping in and out of pages).

At this time the program's memory requirements remain constant at around few MBs though (which is expected). I observed that the cache usage in the memory increases rapidly as the program progresses and keeps growing through the life of the program. How can I tell Windows not to cache these files or folders and is it even possible?

Just a guess, but you might just be trashing/filling the file cache with files that do not need to be used again. This would slow down the system, because it must read files from disk. Also the disk would be in use while it was doing this.

You could try using the Win32 API and CreateFile with the file flag FILE_FLAG_NO_BUFFERING so that is does not cache files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM