C4 Engine Terathon Software C4 Engine API Documentation

• Utility Library

API Links
Developer Links

class Array

Defined in:  C4Array.h
The Array class represents a dynamically resizable array of objects for which any entry can be accessed in constant time.
Definition

template <typename type> class Array

Member Functions
Array::GetElementCount Returns the current size of an array.
Array::SetElementCount Sets the current size of an array.
Array::AddElement Adds an object to the end of an array.
Array::InsertElement Inserts an object into an array.
Array::RemoveElement Removes an object from an array.
Array::Purge Removes all objects from an array.
Array::FindElement Finds a specific element in an array.
Template Parameters
type The type of the class that can be stored in the array.
Constructor

explicit Array(long count = 0, long expand = 0);

Parameters
count The number of objects for which space is initially reserved in the array's storage.
expand The minimum amount of space, as a number of objects, by which the array storage grows when adding a new object requires space to be reallocated.
Description
The Array class represents a homogeneous array of objects whose type is given by the type template parameter. Upon construction, the initial size of the array is zero, but space is reserved for the number of objects given by the count parameter. The array is stored contiguously in memory, allowing constant-time random access to its elements.

As elements are added to the array (using the Array::AddElement function), the storage size is automatically increased to a size somewhat larger than that needed to store the new element. The cost of adding an element is thus amortized linear time.

An Array object can be implicitly converted to a pointer to its first element. This allows the use of the [] operator to access individual elements of the array.