Dec 232017
 
This modification to the Borland Turbo Access routines avoids superfluous rewriting of the header record in a file if the file has not been modified.
File NOMOD.ZIP from The Programmer’s Corner in
Category Pascal Source Code
This modification to the Borland Turbo Access routines avoids superfluous rewriting of the header record in a file if the file has not been modified.
File Name File Size Zip Size Zip Type
NOMOD.DOC 5521 2097 deflated

Download File NOMOD.ZIP Here

Contents of the NOMOD.DOC file


NOMOD.DOC
by
Richard Maine
Compuserve ID: 70127,2750
[email protected]
(aka ames-pioneer.ARPA)

24 Jul 88

This modification to the Borland Turbo Access routines avoids
superfluous rewriting of the header record in a file if the
file has not been modified. With the original Borland code,
the header record of a Turbo Access file is rewritten whenever
the file is closed by calling CloseFile (or CloseIndex or
TAClose).

There are plenty of applications where you open a database to
access data in it without changing the data. In such cases,
there is no need to rewrite the header when the file is closed.
Rewriting the header unnecessarily can cause two kinds of
problems.

First, any time you write on a file, you raise the possibility
of trashing the file even if you were "supposed" to write
data identical to what was already there. The file could be
trashed through software problems, hardware failures, user
errors (like opening the floppy drive door during the write),
or some combination of these. True, the likelihood of these
problems might be low, but minimizing the effects of even
"unlikely" problems leads to more reliable and robust programs.

Second, if you use incremental backup procedures or other
things that check the file modification date, they will be
consider the file to be modified. This can lead to lots
of unneeded backups. For instance, I have a database that
keeps track of the approximately 6000 titles (including
short stories) in my science fiction library. This database
occupies over a megabyte and is examined much more often than
it is updated. Since I am still limping along with 360k floppies
as my only removable storage media, it is a real nuisance to
find that my incremental backup is including this database
even when it has not really been updated.

Of course, if you have a hard disk but don't do backups of it,
neither of the above problems are significant. The issue
of incremental backups is irrelevant, and you have much more
important failure modes that you should be worrying about.

It is possible to avoid the superfluous writes by not calling
CloseFile (or CloseIndex or TAClose) unless you have modified
the file, but this is generally a bad idea. The most obvious
reason is that the file may well be trashed if you have modified
it and forget to close it properly. In multi-user and network
environments there may be other effects.

My modification has the Turbo Access routines keep track of
whether the file has been modified. If the file has not
otherwise been modified, the CloseFile procedure does not
rewrite the header record. This modification does not affect
the use of the Turbo Access routines in any way. It is
applicable whether you are using the low-level or high-level
routines.

The modifications are simple, both in concept and implementation.
The following describes the modifications for version 4.0 of
the Turbo Pascal DataBase Toolbox for IBM PCs and clones.
Previous versions of the toolbox can be modified along
similar lines (in fact there is one less spot to modify because
the MakeIndex routine uses MakeFile and does not need a separate
patch). I presume that similar modifications would apply to
the versions for other machines and languages, but I have not
checked.

1. Add a boolean called Modified to the end of the DataFile
record definition.

2. Initialize DatF.Modified to false in OpenFile and
Idxf.DatF.Modified to false in OpenIndex.

3. Initialize Datf.Modified to true in MakeFile and
Idxf.DatF.Modified to true MakeIndex.

4. Set DatF.Modified to true in PutRec.

5. In PutFileHeader, skip everything if unless DatF.Modified is
true. Also, reset DatF.Modified to false at the end.


The modifications are show in context below.
All are in the file TACCESS.PAS

In public type declarations...
------------------------------
type
DataFile = record
F : file;
FirstFree,
NumberFree,
Int1 : LongInt;
ItemSize : word;
NumRec : LongInt;
Modified : boolean; {Added 3 Mar 88, Richard Maine}
end;


In putRec........
-----------------
BlockWrite(DatF.F,Buffer,1, BlocksWritten);
DatF.Modified := true; {Added 3 Mar 88, Richard Maine}

In MakeFile...
--------------
Rewrite(DatF.F,RecLen);
DatF.Modified := true; {Added 3 Mar 88, Richard Maine}

In OpenFile...
--------------
Reset(DatF.F,RecLen);
DatF.Modified := false; {Added 3 Mar 88, Richard Maine}

In PutFileHeader...
-------------------
procedure PutFileHeader(var DatF : DataFile);
begin
if DatF.Modified then begin {Added 3 Mar 88, Richard Maine}
FillChar(TaRecBuf^, SizeOf(TaRecBuf^), 0);
Move(DatF.FirstFree,TaRecBuf^,FileHeaderSize);
PutRec(DatF,0,TaRecBuf^);
end {if};
DatF.Modified := false;
end; { PutFileHeader }

In MakeIndex...
---------------
Rewrite(F, K);
Modified := true; {Added 3 Mar 88, Richard Maine}

In OpenIndex...
---------------
Reset(F, K);
Modified := false; {Added 3 Mar 88, Richard Maine}


 December 23, 2017  Add comments

Leave a Reply