Article View: net.bugs
Article #103Reading characters a block at a time in Berkeley Pascal
From: 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
Technical Details
Message-ID:
<bnews.decwrl.1364>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
From: utzoo!decvax!decwrl!baskett Newsgroups: net.bugs Title: Reading characters a block at a time in Berkeley Pascal Article-I.D.: decwrl.1364 Posted: Sat Apr 9 15:05:07 1983 Received: Sun Apr 10 06:22:53 1983 Subject: Reading characters a block at a time in Berkeley Pascal Date: Sat, 09 Apr 1983 15:05:07 +0000 Message-ID: <bnews.decwrl.1364>