Tools.h++ Manual

104011 Tandem Computers Incorporated 22-123
22
RWTValVirtualArray<T>
Synopsis
#include <rw/tvrtarry.h>
RWVirtualPageHeap* heap;
RWTValVirtualArray<T> array(1000L, heap);
Description This class represents a virtual array of elements of type
T
of almost any length.
Individual elements are brought into physical memory on an "as needed" basis.
If an element is used as an lvalue it is automatically marked as "dirty" and will
be rewritten to the swapping medium.
The swap space is provided by an abstract page heap which is specified by the
constructor. Any number of virtual arrays can use the same abstract page
heap. You must take care that the destructor of the abstract page heap is not
called before all virtual arrays built from it have been destroyed.
The class supports reference counting using a copy-on-write technique, so (for
example) returning a virtual array by value from a function is as efficient as it
can be. Be aware, however, that if the copy-on-write machinery finds that a
copy must ultimately be made, then for large arrays this could take quite a bit
of time.
For efficiency, more than one element can (and should) be put on a page. The
actual number of elements is equal to the page size divided by the element
size, rounded downwards. Example: for a page size of 512 bytes, and an
element size of 8, then 64 elements would be put on a page.
The indexing operator (
operator[](long)
) actually returns an object of type
RWTVirtualElement<T>
. Consider this example:
double d = vec[j];
vec[i] = 22.0;
Assume that vec is of type
RWTValVirtualArray<double>
. The expression
vec[j]
will return an object of type
RWTVirtualElement<double>
, which
will contain a reference to the element being addressed. In the first line, this
expression is being used to initialize a double. The class
RWTVirtualElement<T>
contains a type conversion operator to convert itself
to a T, in this case a double. The compiler uses this to initialize
d
. In the