#include <RslPlugin.h>
Public Member Functions | |
virtual unsigned int | GetLength () const =0 |
Get the current length. | |
virtual unsigned int | GetCapacity () const =0 |
Get the current capacity. | |
virtual void | Resize (unsigned int n)=0 |
Resize this array, copying the existing array elements if necessary. | |
virtual void | Reserve (unsigned int n)=0 |
Reserve storage, increasing the capacity of the array without changing its length. | |
Protected Member Functions | |
virtual | ~RslResizer () |
Destructor is for internal use only. |
The following example demonstrates how to push and pop values on a resizable array (which might or might not be varying).
int Push(RslContext* ctx, int argc, const RslArg** argv) { assert(argv[1]->IsResizable()); RslResizer* resizer = argv[1]->GetResizer(); unsigned int oldLength = resizer->GetLength(); resizer->Resize(oldLength+1); RslFloatArrayIter array(argv[1]); RslFloatIter arg(argv[2]); unsigned int numPoints = argv[1]->NumValues(); for (int i = 0; i < numPoints; ++i) { array[oldLength] = *arg; ++array; ++arg; } return 0; } int MyPop(RslContext* ctx, int argc, const RslArg** argv) { assert(argv[1]->IsResizable()); RslFloatIter result(argv[0]); assert(argv[1]->IsArray() && argv[1]->IsFloat()); RslFloatArrayIter array(argv[1]); unsigned int n = array.GetLength()-1; unsigned int numPoints = argv[0]->NumValues(); for (int i = 0; i < numPoints; ++i) { *result = array[n]; ++result; ++array; } RslResizer* resizer = argv[1]->GetResizer(); resizer->Resize(n); return 0; }
Resizing an array might invalidate an existing array iterator, so beware. In addition to the Resize() method, a Reserve() method is also available. This allows the capacity of a an arry to be increased without changing its length, which amortizes allocation costs when pushing multiple values.
|
Destructor is for internal use only.
|
|
Get the current capacity.
|
|
Get the current length.
|
|
Reserve storage, increasing the capacity of the array without changing its length. This is useful when pushing multiple values to amortize allocation costs. Specifying a value lower than the current capacity has no effect, unless it is reduced to zero, in which case storage is reclaimed. |
|
Resize this array, copying the existing array elements if necessary. If the length is increased, the new elements are uninitialized. Resizing an array increases its capacity if necessary. However, reducing the length does not decrease the capacity (unless it is set to zero, in which case the storage is reclaimed). |