File Read Cache - How to purge?

Marc 'BlackJack' Rintsch bj_666 at
Tue Aug 21 10:15:44 CEST 2007

On Mon, 20 Aug 2007 21:06:43 -0700, Signal wrote:

> 1. I don't quite understand how after one full read of a file, another
> full read of the same file is "cached" so significantly while
> consuming so little memory. What exactly is being cached to improve
> the reading of the file a second time?

What do you mean by so little memory?  It (the whole file) is cached by the
operating system totally independent of your program, so the memory used
does of course not show up in the memory stats of your program.  Just
think about this: some file `a.dat` is cached by the OS and you start a
program that might eventually read that file.  The memory is used already
*before* the program starts and the OS does not know in advance which
files will be read by the program.  So how, why and when should the memory
used for the cache should be added to the programs memory stats.

> 2. Is there anyway to somehow to take advantage of this "caching" by
> initializing it without reading through the entire file first?

You mean reading the file without actually reading it!?  :-)

> 3. If the answer to #2 is No, then is there a way to purge this
> "cache" in order to get a more accurate result in my routine?  That is
> without having to read another large file first?


	Marc 'BlackJack' Rintsch

More information about the Python-list mailing list