HTBasic Help
×
Menu
Index

Buffers

 
Buffer I/O is more powerful than String I/O. HTBasic implements circular buffers. Fill and empty pointers remember where the last OUTPUT, ENTER, or TRANSFER ended allowing the next statement to pick up where the last one left off. The ASSIGN statement sets up a buffer for I/O.
 
For example:
 
ASSIGN @Iopath TO BUFFER [300] !creates an unnamed buffer and assigns it an I/O path name
ASSIGN @Another TO BUFFER X(*) ! assigns an I/O path name to a previously declared variable
 
The buffer specified in ASSIGN may now be used in ENTER, OUTPUT, and TRANSFER statements. Information kept about a BUFFER includes the current number of bytes in the buffer (initially set to 0), the empty and fill pointers (initially set to 1), the buffer capacity, and TRANSFER information.
 
If somehow a BUFFER ceased to exist while the I/O path used to write to it still existed, fatal errors could result. For this reason, the BUFFER lifetime must equal or exceed the I/O path lifetime. The following table shows the legal and illegal combinations of BUFFERs and I/O paths. A value of 0 means the combination is legal. A non-zero value gives the error returned if this combination is used.
 
Type of BUFFER
Local
Type of I/O Path COM
Parameter
Local
0
602
602
Same COM
-
0
-
Different COM
 
 
-
602
Parameter
0
602
0*
Un-named
0
602
602
ALLOCATE
603
603
603
Not a BUFFER
603
603
603
 
*If the I/O path and BUFFER parameters have been passed through multiple CALL levels, the BUFFER must outlive the I/O path. Also, if a parameter originated as a COM variable, the rules for COM variables apply.
 
Unnamed buffers can only be accessed through their I/O path. Named buffers can be directly accessed through their variable’s name, but this procedure is not recommended since the data in the buffer is unformatted, the data may have the wrong byte order, and direct access does not automatically update the buffer registers. The data in the buffer and the string’s current length can be changed, but the buffer registers (empty and fill pointers, current-number-of-bytes register) are not automatically updated. To automatically update the buffer registers use ENTER, OUTPUT, and TRANSFER statements.