KB#00628-How to improve READ/WRITE time to an ASCII file
How to improve READ/WRITE time to an ASCII file
When reading an ASCII file, PRO/5 reads one byte at a time. This method isn't very fast, and can cause programs that rely on ASCII files to run very slowly.
The best way to increase speed is to implement the SIZ mode on the IO statements. This way, you can read and/or write much larger chunks of data which will make a dramatic improvement. It's usually typical to use a large SIZ value such as 512 or 1024.
One important consideration is that your code will have to change to accommodate this feature. This is best demonstrated by an example:
The ASCII File:
The old P5 program:
The new P5 program:
With the old program, P5 would read a byte at a time until it hit a line terminator. Therefore, the value of a$ would be "one". However, the new way of doing it will read in up to 512 bytes. Because the file is less than 512 bytes, the entire contents of the file are loaded into a$. That means that a$ has all three 'records' and their terminators in it. Therefore, it's necessary to add a parsing algorithm to your code to separate the records from one another. The other thing is that it's very likely that you'll end up with a partial record at the end of your variable. For example, if the read record used a SIZ of 5, then a$ would be the full record "one" (3 bytes), the line terminator (1 byte), and the first letter of the second record - "t" (one more byte). This may seem like a big problem, but can be easily addressed by a good parsing routine.
Here's a good example provided by Falk Spitzberg:
if eof = 1
Tmp = pos($0a$=buffer$)
then rec$ = buffer$(1,tmp-1),buffer$=Buffer$(Tmp+1); return
eof = 1
This example uses the GET_REC subroutine to parse out a full record if there is one, and to read more information from the file if the variable doesn't have a full record.
Last Modified: 02/23/2004 Product: PRO/5 Operating System: N/A
BASIS structures five components of their technology into the BBx Generations.