[comp.lang.misc] buffering, was Query

johnl@esegue.segue.boston.ma.us (John R. Levine) (08/22/90)

In article <60345@lanl.gov> jlg@lanl.gov (Jim Giles) writes:
>From article <126800008@.Prime.COM>, by EAF@.Prime.COM:
>> If your language I/O library is intelligent and you are reading sequential
>> data, the language library will call on the OS to read the next disk 
>> block into memory, often before it is required.
>
>Not on UNIX it won't.  There is no system call for the library to use ...

Unix systems have, for over ten years, had the following useful little hack:
It keeps track of the last block you read from each open file.  If you are
reading block N, and the last block you read was N-1, then the system out of
sheer optimism tells the disk to pre-read block N+1.  This brings the magic
of double buffering to any program that reads a file sequentially, whether it
uses an I/O library or just does read() system calls.  Buffered writing
happens, too, since write system calls don't wait for the physical I/O to
complete.

-- 
John R. Levine, Segue Software, POB 349, Cambridge MA 02238, +1 617 864 9650
johnl@esegue.segue.boston.ma.us, {ima|spdcc|world}!esegue!johnl
Marlon Brando and Doris Day were born on the same day.