Author Topic: How does one invalidate the file cache?  (Read 353 times)

thehay95

  • Regular Member
  • *
  • Posts: 1
How does one invalidate the file cache?
« on: August 22, 2018, 06:23:15 PM »
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.
dich vu dich vu chuyen nha tron goi, gioi thieu giup viec nha gia re

jj2007

  • Member
  • *****
  • Posts: 8822
  • Assembler is fun ;-)
    • MasmBasic
Re: How does one invalidate the file cache?
« Reply #1 on: August 22, 2018, 07:51:26 PM »
See ClearFileCache.

FindFirstFile is the only viable way. It's not that slow, actually, provided the info is already in the cache.

AW

  • Member
  • *****
  • Posts: 1561
  • Let's Make ASM Great Again!
Re: How does one invalidate the file cache?
« Reply #2 on: August 22, 2018, 10:47:20 PM »
You have the FlushFileBuffers

jj2007

  • Member
  • *****
  • Posts: 8822
  • Assembler is fun ;-)
    • MasmBasic
Re: How does one invalidate the file cache?
« Reply #3 on: August 22, 2018, 11:17:47 PM »
You have the FlushFileBuffers

You have ideas :t
How would you use it?

AW

  • Member
  • *****
  • Posts: 1561
  • Let's Make ASM Great Again!
Re: How does one invalidate the file cache?
« Reply #4 on: August 23, 2018, 05:33:05 AM »
I have used it only with pipes. I have no clear scenario to use it with files or folders - usually the cache is pretty intelligent. However, in a particularly busy system, we may need to force it to flush right away.

jj2007

  • Member
  • *****
  • Posts: 8822
  • Assembler is fun ;-)
    • MasmBasic
Re: How does one invalidate the file cache?
« Reply #5 on: August 23, 2018, 08:13:17 AM »
I have no clear scenario

I have a testbed (loops=1000):

  NanoTimer()
  For_ ct=0 To loops-1
        Open "U", #1, edi
        invoke FlushFileBuffers, MbFH[4]
        Let esi=Input$(#1, Min(MbBufSize/4, Lof(#1)))
        Close #1
  Next
  Inkey NanoTimer$(), " for FlushFileBuffers & file read"


Code: [Select]
67 ms for cached file read
3565 ms for ClearFileCache + file read
417 ms for FlushFileBuffers & file read