Tools.h++ Manual
10-2 104011 Tandem Computers Incorporated
10
10.2 Member functions
The class
RWFileManager
adds four additional member functions to those of
class
RWFile
. They are:
1.
RWoffset allocate(RWspace s);
Allocate
s
bytes of storage in the file, returning the offset to the start of the
allocation.
2.
void deallocate(RWoffset t);
Deallocate (free) the storage space starting at offset
t
. This space must have
been previously allocated by the function
allocate()
:
3.
RWOffset endData();
Return the offset to the last data in the file.
4.
RWoffset start();
Return the offset from the start of the file to the first space ever allocated by
this
RWFileManager
, or return
RWNIL
1
if no space has been allocated,
implying that this is a "new file".
The statement
RWoffset a = F.allocate(sizeof(double));
uses
RWFileManager F
to allocate the space required to store an object with
the size of a double and returns the offset to that space. To write the object to
the disk file, you should seek to the allocated location and then use
Write()
.
It is an error to read or write to an unallocated location in the file. It is also
your responsibility to maintain a record of the offsets necessary to read the
stored object.
To help you do this, the first allocation ever made by a
RWFileManager
is
considered "special" and can be returned by member function
start()
at any
time. The
RWFileManager
will not allow you to deallocate it. This first block
will typically hold information necessary to read the remaining data, perhaps
the offset of a root node, or the head of a linked-list.
1.
RWNIL
is a macro whose actual value is system dependent. Typically , it is
-1L
.