News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How does one invalidate the file cache?

Started by xanatose, November 10, 2014, 06:11:43 AM

Previous topic - Next topic

xanatose

Using win32 api. How does one invalidate the file cache? I'm trying to solve a performance bug that occurs only when the files are not in the cache.

Also:
Is there something faster than FindFirstFile and FindNextFile to enumerate files in a directory. I only need the name of the files.


MichaelW

For what it's worth, I did a quick test to determine if the FlushFileBuffers function, when passed a handle to a volume, clears the file data from the cache, and my results indicated that it does not.
Well Microsoft, here's another nice mess you've gotten us into.

TouEnMasm


The createfile function with the option FILE_FLAG_NO_BUFFERING must do it.

Fa is a musical note to play with CL

MtheK

  That works for me, tho the data must be aligned, else rc87 (ERROR_INVALID_PARAMETER) will occur.

Tedd

I wouldn't expect you can invalidate the cache, as such. Writing to it would make it 'dirty,' but the cache would still be valid.
Flushing the buffers does exactly what is says -- it flushes the cache to file, so the file is updated; the cache still remains and is still valid.
FILE_FLAG_NO_BUFFERING avoids the use of cache, which will only serve to slow down all access in your case.
If your issue is an actual bug due to timing and delays caused by files not yet being ready, your solution should be in synchronisation, not hacking in an attempt to hide the issue. If it's not really a bug, and you're just noticing a slow-down on not-yet-cached files, invalidating the cache would have the opposite effect -- you could try pre-loading the next file as you start to process the current one (in a separate thread, or using overlapped file IO.)

FindFirstFile/FindNextFile are a little slow, but I don't know of another generic way to get a directory listing of files. There is a potentially faster method for NTFS using the "Change Journal," but it works on NTFS volumes only.
Again, preparation may be required if you're looking for optimal performance.
Potato2

xanatose

The simulation of the slow down (when the files are not in the cache) was what I needed.

Ended up writing the files to a DVD. Reading them from there and opening/closing the drive after each test.
Not clean, but worked for my tests.

Thanks everyone that responded.