OPEN LEN=reclen Effect on Sequential File Buffering and Speed (22021)






This article was previously published under Q22021

SUMMARY

QuickBasic Versions 2.00, 2.01, and 3.00 don't behave according to the following statement on Page 370 of the "Microsoft QuickBasic Compiler" manual for Versions 2.00, 2.01, and 3.00, which discusses the recordlength option of the OPEN statement for sequential files:

When used to open a sequential file, recordlength specifies the number of characters to be loaded to the buffer before it is written to, or read from, the disk. A larger buffer means more room taken from Basic, but faster file I/O.

Changing the LEN=reclen statement will not change the sequential file-access speed or buffering for QuickBasic Versions 2.00, 2.01, or 3.00, but WILL change speed and buffering for QuickBasic 4.00 and later versions.

For greater file-access speed, boot with a BUFFERS=20 statement in your CONFIG.SYS file (DOS configuration file) on the root directory of your start-up disk.

MORE INFORMATION

Please note that in QuickBasic Versions 4.00, 4.00b, and 4.50 for MS-DOS, Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and OS/2, and Microsoft Basic Professional Development System (PDS) Version 7.00, the LEN=reclen statement changes both the buffer size and sequential file-access speed. The default sequential-access buffer size is 512 bytes in these versions.

The 512-byte size gives fast disk input/output speed because it matches the sector size or a multiple of the sector size for most disk drives. This is correctly documented in the "Microsoft QuickBasic 4.0: Basic Language Reference" manual for Versions 4.00 and 4.00b.

By changing LEN=256 to LEN=10 or LEN=1000 in the following program, no file-output buffering or speed changes are apparent in QuickBasic 2.x and 3.00 when you watch the disk-access light on the drive. However, you will notice buffering and speed changes in later QuickBasic versions:
   PRINT "Start of program"
   OPEN "buf.dat" FOR OUTPUT AS #1 LEN=256
   PRINT "File was just opened"
   WHILE INKEY$="":WEND
   FOR Index% = 1 to 30
   PRINT "Record number --> ";Index%
   WRITE #1, STRING$(79,CHR$(48+Index%))
   WHILE INKEY$="":WEND
   NEXT Index%
   CLOSE #1
   END
				

Modification Type: Minor Last Reviewed: 1/9/2003
Keywords: KB22021