#include <gauge3d/array.h>
Public Methods | |
GStridedArray () | |
Create NULL array. | |
GStridedArray (tType *ptr,int stride) | |
Create array that starts at ptr with given stride. | |
GStridedArray (tType *ptr) | |
Create array using non-strided data. | |
const tType& | operator[] (int index)const |
Array access. | |
tType& | operator[] (int index) |
Array access. | |
int | Stride () |
Get the stride. | |
operator tType * ()const | |
Cast to type. | |
bool | operator== (const void *other) |
Test for equality with pointer. |
This class allows you to create an array with space between the elements. This is useful for interleaved data, where you have two types of interleaved into one big array.
The stride of the array is the distance in bytes between the beginning of one array element and the beginning of the next. For example, say you wanted to interleave a set of vertex positions and normals. So, you have an array: GVector* data = new GVector[numVertices * 2]; In that array, the even-numbered elements are vertex positions while the odd-numbered elements are vertex normals (starting at zero). Then, you could create two strided arrays like so: GStridedArray<GVector> vertices(data, sizeof(GVector)*2); GStridedArray<GVector> normals(data + 1, sizeof(GVector)*2); Then, you could access "vertices" and "normals" as if they were regular arrays.
Note that GStridedArray is NOT reference-counted, unlike GArray.