Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Tools Module Reference Guide

RWTValVirtualArray<T>

Module:  Essential Tools Module   Group:  Traditional Collection


Does not inherit

Local Index

Members

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 as needed basis. If an element is updated it is automatically marked as "dirty" and will be rewritten to the swapping medium.


NOTE -- RWTValVirtualArray will be deprecated.

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:

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:

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.

Program output:

Public Constructors

RWTValVirtualArray<T>(long size, RWVirtualPageHeap* heap);
RWTValVirtualArray<T>(const RWTValVirtualArray<T>& v);
RWTValVirtualArray<T>(const RWTVirtualSlice<T>& sl);

Public Destructors

~RWTValVirtualArray<T>();

Public Operators

RWTValVirtualArray&
operator=(const RWTValVirtualArray<T>& v); 
void
operator=(const RWTVirtualSlice<T>& sl);
T
operator=(const T& val); 
T
operator[](long i) const; 
RWTVirtualElement<T>
operator[](long);

Public Member Functions

RWVirtualPageHeap*
heap() const; 
long
length() const; 
void
reshape(long newLength); 
void
set(long i, const T& v); 
RWTVirtualSlice<T>
slice(long start, long length); 
T
val(long i) const; 


Previous fileTop of DocumentContentsIndex pageNext file

©2004 Copyright Quovadx, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.