Please enable JavaScript to view this site.

ESL Documentation

FILEIO Subroutine

Change the size of the I/O buffer.

call SetBufferSize(FILE_ID_IV, BUFFER_SIZE_IV)

FILE_ID_IV

An integer variable for the file id.

BUFFER_SIZE_IV

An integer variable containing the buffer size in bytes.

Description

SetBufferSize( ) allows you to modify the buffers used by the File I/O input subroutines to keep track of the number of lines in a file. This allows you to adjust the size of the buffer to optimize the speed at which the file is read, while keeping the buffer size as small as possible.

Program speed can be improved in some cases by increasing the buffer size or the index buffer size for one or more files. Conversely, the amount of memory needed can be reduced by decreasing the buffer size or the index buffer size for one or more files. The default value for each parameter is 1K. If you choose to resize the buffers, make the modifications only once, just after opening the file.

Decreasing the buffer size can cause a degradation of response time. Since the buffer fills up more often, the input subroutines must scan the file multiple times. If the buffer is sized to less than the length of a line, the input subroutines will attempt to increase the buffer to the next larger increment of 1K. If unsuccessful, the line will not be read.

Buffer size also affects WriteRecord( ), which first collects all of the fields of the record in the buffer, and then writes the buffer's contents all at once. If the buffer is too small to hold the whole record, WriteRecord( ) will attempt to increase the buffer to the next larger increment of 1K. If unsuccessful, the record will not be written.

Increasing the buffer size will improve speed, but always increase the buffer size to a multiple of 1K, or response time may actually be slowed. The buffer size can be a maximum of 64K. If a request is made for more than 64K, a buffer of 64K will be allocated.

Errors

FIO_E_NOTOPEN

File has not been opened. A file must be opened before a read attempt is made.

FIO_E_REALLOCMEM

Insufficient system memory. Not enough system memory to set buffer or index to size requested.

Example

integer FileID

integer BufferSize is 1024

integer IndexSize is 1024

integer TabSize is 5

include "fileio.inc"

 

# To be brief, error handling is omitted

response to line "Double Buffer" from keyboard

 copy (BufferSize * 2) to BufferSize

 call SetBufferSize (FileID, BufferSize)

 

response to line "Halve Buffer" from keyboard

 copy (BufferSize / 2) to BufferSize

 call SetBufferSize (FileID, BufferSize)

 

response to line "Double Index Size" from keyboard

 copy (IndexSize * 2) to IndexSize

 call SetIndexSize (FileID, IndexSize)

 

response to line "Halve Index Size" from keyboard

 copy (IndexSize / 2) to IndexSize

 call SetIndexSize (FileID, IndexSize)

 

response to line "Set Tab Size" from keyboard

 call SetTabSize (FileID, TabSize)