Tools.h++ Class Reference

Table Of Contents
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 first line. In the second line, the
expression vec[i] is being used as an lvalue. In this case, the compiler uses the assignment
operator for RWTVirtualElement<T>. This assignment operator recognizes that the expression
is being used as an lvalue and automatically marks the appropriate page as "dirty," thus
guaranteeing that it will be written back out to the swapping medium.
Slices, as well as individual elements, can also be addressed. These should be used wherever
possible as they are much more efficient because they allow a page to be locked and used
multiple times before unlocking.
The class T must have:
well-defined copy semantics (T::T(const T&) or equiv.);
well-defined assignment semantics (T::operator=(const T&) or equiv.).
In addition, you must never take the address of an element.
Persistence
None
Example
In this example, a virtual vector of objects of type ErsatzInt is exercised. A disk-based page
heap is used for swapping space.
#include <rw/tvrtarry.h>
#include <rw/rstream.h>
#include <rw/diskpage.h>
#include <stdlib.h>
#include <stdio.h>
struct ErsatzInt {
char buf[8];
ErsatzInt(int i) { sprintf(buf, "%d", i); }