Thread View: net.bugs
1 messages
1 total messages
Started by utzoodecvaxdecwrlbaskett
Sat, 09 Apr 1983 15:05
Reading characters a block at a time in Berkeley Pascal
Author: utzoodecvaxdecwrlbaskett
Date: Sat, 09 Apr 1983 15:05
Date: Sat, 09 Apr 1983 15:05
29 lines
1666 bytes
1666 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads