File Open and Close

The file control environment consists of a number of structures containing all the parameters required to access the file. Each time a file is opened or closed, these data structures have to be manipulated, the amount of execution time increasing with the number of open files.

Certain operations, although not explicit file open or file close, manipulate these data structures and should also be considered. These are:

Beware of constructs in which assignment of file variables may not be obvious, such as:

OPEN . . . TO F1 . . .
OPEN . . . TO F2 . . .
. . .
X=F1
GOSUB 1000
X=F2
GOSUB 1000
. . .
1000 REM SUBR: PROCESS FILE
. . .

Remote Files

The overhead of opening remote files is considerably higher than that of local files. The elapsed time taken to open a remote file depends on the type of network being used, and can be very noticeable when using a wide area network.

Any performance problems caused by the way files are opened and closed within programs become considerably worse when the files are remote, therefore more care must be taken if remote files are, or may be, used.

Reality Files

On Reality, files are stored in the UNIX or Windows file system (as appropriate), thus opening a file in the Reality environment results in a corresponding file open in the UNIX or Windows environment. This results in a noticeable overhead when opening and closing files, thus exaggerating any performance problems with file open and close.

Deferred Close

REALITY 7.2 and all releases of Reality on UNIX and Windows implement a deferred close mechanism to reduce the overheads in applications that repeatedly open and close a set of files. This works by retaining the data structures, but marking them as closed, so that reopening the file does not have to rebuild them.

Opening Multiple Files

If many files are to be opened, choose carefully the point in the program where the files are opened. There are two approaches:

The most appropriate approach depends on the application, and a combination of the two may be the best solution.

Considerations for Efficiency

To avoid performance problems associated with opening and closing files: