Figure 10.6 File of Figure 10.4, with record 3 deleted and final record moved.
deleted record, and to wait for a subsequent insertion before reusing the space.
A simple marker on a deleted record is not sufficient, since it is hard to find this
available space when an insertion is being done. Thus, we need to introduce an
additional structure.
At the beginning of the file, we allocate a certain number of bytes as a file
header. The header will contain a variety of information about the file. For now, all
we need to store there is the address of the first record whose contents are deleted.
We use this first record to store the address of the second available record, and so
on. Intuitively, we can think of these stored addresses as pointers, since they point
to the location of a record. The deleted records thus form a linked list, which is
often referred to as a free list. Figure 10.7 shows the file of Figure 10.4, with the
free list, after records 1, 4, and 6 have been deleted.
On insertion of a new record, we use the record pointed to by the header.
We change the header pointer to point to the next available record. If no space is
available, we add the new record to the end of the file.
Insertion and deletion for files of fixed-length records are simple to implement,
because the space made available by a deleted record is exactly the space
needed to insert a record. If we allow records of variable length in a file, this
match no longer holds. An inserted record may not fit in the space left free by a
deleted record, or it may fill only part of that space.