2

My program knows in advance that it will access certain (many/large) files or directories in the future. Is there an intended mechanism to pass this information on to Windows so it can load these into a buffer? Or do I have to open the files myself in a background thread?

mafu
  • 31,798
  • 42
  • 154
  • 247

1 Answers1

4

That is the "everybody would use it if they could" function. Similar to the WS_EX_SUPER_TOPMOST window style flag and the NIF_NEXT_TO_THE_CLOCK options for the NOTIFYICONDATA.uFlags option value. Not available either.

It's not like you couldn't cheat the system, big companies are not ashamed about it. Looking at you Adobe. You have free reign of the machine once you coax a user to run your installer. So you can install a program that runs at login and doesn't do anything but load all the DLLs that your program needs. You call it "optimizer" to make the user feel good about it. Even though Prefetch is fooled by it, it is also rather important that you publish monthly Critical Security Updates so you can put it back when the user removed it.

The word "coax" is the operative one though, most users stopped trusting their machines 15 years ago. Well, no, they stopped trusting programmers. That will never come back, big shame.


If this is actually needed for a file that you don't need at startup like an implicitly loaded DLL or a data file you need to read to make your program useful, and can foresee the need for a file some time in the future, then the linked duplicate is a solution.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • But but... I _promise_ I would not abuse it! – mafu Sep 15 '13 at 23:00
  • Out of curiosity: Wasn't the exact same thing also implemented in Office 2000? So I guess this understanding and the subsequent policy is relatively new. – mafu Sep 15 '13 at 23:03
  • I guess this understanding is *wrong*, since Microsoft did add such a function. Answer added to linked question. – Ben Voigt Sep 19 '13 at 17:51
  • BTW, having explicit prefetch requests is greatly superior to the "run optimizer at startup" method, from the user's perspective, since the OS could see whether the data actually is accessed soon after, and start ignoring deprioritizing prefetch requests from programs that abuse it. Not to mention that all prefetch requests can by default be given lower priority than synchronous I/O (although if the program is proven to have really good prediction, it might make sense for the priority to increase). – Ben Voigt Sep 19 '13 at 20:23