tags:

views:

104

answers:

4

I'm writing a disk intensive win32 program. The first time it runs, it runs a lot slower while it scans the user's folders using FindFirstFile()/FindNextFile().

How can I repeat this first time performance without rebooting? Is there any way to force the system to discard everything in its disk cache?

I know that if I were reading a single file, I can disable caching by passing the FILE_FLAG_NO_BUFFERING flag to a call to CreateFile(). But it doesn't seem possible to do this when searching for files.

A: 

You could avoid a physical reboot by using a virtual machine.

Peter G.
+1  A: 

You need to create enough memory pressure to cause the memory manager and cache manager to discard the previously caches results. For the cache manager, you could try to open a large (I.e. Bigger than physical ram) file with caching enabled and then read it backwards (to avoid any sequential I/o optimizations). The interactions between vm and cache manager are a little more complex and much more dependent on os version.

There are also caches on the controller (possibly, but unlikely) and on the disk drive itself (likely). There are specific IoCtls to flush this cache, but in my experience, disk firmware is untested in this arena.

MJZ
A: 

Have you thought about doing it on a different volume, and dismounting / remounting the volume? That will cause the vast majority of everything to be re-read from disk (though the cache down there won't care).

jrtipton
A: 

Check out the Clear function of CacheSet by SysInternals.

On Freund
I tried it on Windows XP and enumerating through disk folders was just as fast after clearing the cache as before, so it seemed not to work.
Steve Hanov