[comp.sys.mac.programmer] Optimal buffer size

palarson@watdragon.waterloo.edu (Paul Larson) (06/02/88)

Could someone tell me what the best size is for reading in blocks from
the disk drives?
Does it even matter, with disk casheing?

Thanks in advance.

Johan Larson, Programmer Aspirant

dan@apple.UUCP (06/02/88)

There is no optimal buffer size that works in all cases and with all
hard disks.

Having said that, I have found (experimentally) that 8K works nicely
with hard disks in the 20 MB range, and I use 32K for some of my fast
text filters that I use on the 40-80MB drives.

That is, I use 32K buffers for stdin and stdout in my MPW Tools, for
example, and IO is dramatically improved.  (After doing an fopen, use
setvbuf)  However, more is NOT always better: 64K buffers are actually
slower!  It all depends on your disk, your application, how many open
files you have, you fragmented your disk is, etc..

Another tip: in MPW, a RAM cache setting (in the Control Panel) of
32-64K has been found to be optimal by Ira Ruben, the author of the MPW
Assembler.  He says 32-64K is the ONLY way to go.  He programs
exclusively using MPW Asm and MPW Pascal.

HOWEVER, using MPW C is a different ballgame.  MPW C does not have
(currently, but it will in 3.0) any load/dump mechanism.  Therefore MPW
C has to read and reread all of the equates files every compile.  This
makes for a lot of disk reading and greatly slows down things.  In that
case, you would like to have all of your header files in RAM, so setting
a RAM cache of about 256K (if you can afford it memory wise) really
helps MPW C.

BOTTOM LINE: experiment with your language and hard disk.  Write a
little tool and do some measuring.  Remember, measure, THEN optimize.

Dan Allen
Software Explorer
Apple Computer