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:
VAR2=VAR1
where VAR1
is a file variable. This causes the
file control structure elements referenced by VAR1
to be duplicated,
and VAR2
set to refer to the duplicate copies. Both variables then
refer to the same file. However, if VAR1
is used in a subsequent
OPEN statement, effectively closing the current file and opening a new
one, VAR2
will still refer to the original file.VAR1=X
where VAR1
is a file
variable. This causes the file referenced by
VAR1
to be closed.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 . . .
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.
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.
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.
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.
To avoid performance problems associated with opening and closing files: