baskett (04/09/83)
Some Pascal programs can be made substantially faster if they can read characters from a file in blocks of more than one character. One method of doing this is by having a file variable whose type is a "file of linebuffer" where "linebuffer = array [1..size] of byte" where "byte = -128..127" or types to that effect. Then reading from this file into a variable of type "linebuffer" will give you "size" characters at a time until the last block. At this point, the current runtime, IOSYNC.c in particular, will do you in. The fix below will let you get the last partial block into the file variable with null fill. So after eof goes true on the file, you can get the last partial block with "x := charfile^;" or some such. In the fix, be sure to note the interchange of the item size and the item count in the fread call. 14a15 > int count; 34c35 < fread(curfile->fileptr, (int)curfile->fsize, 1, curfile->fbuf); --- > count = fread(curfile->fileptr, 1, (int)curfile->fsize, curfile->fbuf); 52c53 < for (ptr = curfile->fileptr; ptr < limit; ) --- > for (ptr = count+(curfile->fileptr); ptr < limit; ) My experiments indicate that a "size" of at least 16 is adequate to get most of the performance benefits possible from this kind of buffering. Forest Baskett