beautypg.com

Member functions – HP Integrity NonStop J-Series User Manual

Page 89

background image

Click on the banner to return to the user guide home page.

©Copyright 1996 Rogue Wave Software

Member Functions

The class

RWFileManager

adds four additional member functions to those of class

RWFile

.

They are:

RWoffset allocate(RWspace s); Allocate s bytes of storage in the file, returning the offset
to the start of the allocation.

1.

void deallocate(RWoffset t); Deallocate (free) the storage space starting at offset t. This
space must have been previously allocated by the function allocate():

2.

RWOffset endData(); Return the offset to the last data in the file.

3.

RWoffset start(); Return the offset from the start of the file to the first space ever allocated
by

RWFileManager

, or return RWNIL

[7]

if no space has been allocated, which implies

that this is a new file.

4.

The statement:

RWoffset a = F.allocate(sizeof(double));

uses F of

RWFileManager

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 use Write(). It is an error to read or write to an unallocated location in
the file.

It is 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 an

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.

The following example shows the use of class

RWFileManager

to construct a linked-list of ints

on disk. The source code is included in the toolexam subdirectory as fmgrsave.cpp and
fmgrrtrv.cpp.

When using this example, you must type a carriage return after the last item you want to insert in
order to guarantee that it will be added to the list. This is because different compilers handle the
occurrence of an EOF on the cin stream differently.

#include // 1

This manual is related to the following products: