Templatized array with bounds checking. The backing storage is either auto-allocated (dynamically allocated) or user-allocated (supplied by user). With exception of changing the size and capacity, all operations are guaranteed to be O(1).
dmArray<int> a;
a.SetCapacity(1);
a.Push(1);
int b = a[0];
get number of elements in C array
Array - [type:]
Number - of elements
The backing storage is either auto-allocated (dynamically allocated) or user-allocated (supplied by user). With exception of changing the size and capacity, all operations are guaranteed to be O(1).
constructor. empty auto-allocated memory
dmArray<int> a;
a.Push(1);
user-allocated array with initial size and capacity
user_array - User-allocated array to be used as storage.
size - Initial size
capacity - Initial capacity
Only frees memory when auto-allocated.
Pointer to the start of the backing storage
pointer - pointer to start of memory
Pointer to the start of the backing storage
pointer - pointer to start of memory
Pointer to the end of the backing storage The end is essentially outside of the used storage.
pointer - pointer to end of memory
Pointer to the end of the backing storage The end is essentially outside of the used storage.
pointer - pointer to end of memory
First element of the array
reference - reference to the first element
First element of the array (const)
reference - const-reference to the first element
Last element of the array
reference - reference to the last element
Last element of the array (const)
reference - const-reference to the last element
Size of the array in elements
number - array size
Capacity is currently allocated storage.
number - array capacity
Check if the array is full. The array is full when the size is equal to the capacity.
boolean - true if the array is full
Check if the array is empty. The array is empty when the size is zero.
boolean - true if the array is empty
Amount of additional elements that can be stored
number - amount of additional elements that can be stored
Retrieve an element by index
index - array index
reference - reference to the element at the specified index
Retrieve an element by index (const)
index - array index
reference - const-reference to the element at the specified index
Set the capacity of the array. If the size is less than the capacity, the array is truncated. If it is larger, the array is extended. Only allowed for auto-allocated arrays and will result in a new dynamic allocation followed by memcpy of the elements.
capacity - capacity of the array
Relative change of capacity Equivalent to SetCapacity(Capacity() + offset). Only allowed for auto-allocated arrays and will result in a new dynamic allocation followed by memcpy of the elements.
offset - relative amount of elements to change the capacity
Set size of the array
size - size of the array, must be less or equal to the capacity
user-allocated array with initial size and capacity
user_array - User-allocated array to be used as storage.
size - Initial size
capacity - Initial capacity
user_allocated - If false, the ownership is transferred to the dmArray
Remove the element at the specified index. The removed element is replaced by the element at the end (if any), thus potentially altering the order. While operation changes the array size, it is guaranteed to be O(1).
index - index of the element to remove
reference - reference to the new element at index
Remove the element by reference The removed element is replaced by the element at the end (if any), thus potentially altering the order. While operation changes the array size, it is guaranteed to be O(1).
element - reference to the element to remove.
reference - reference to the new referenced element
Add an element to the end of the array Only allowed when the capacity is larger than size.
element - element element to add
Add an array of elements to the end of the array Only allowed when the capacity is larger than size + count
array - array of elements to add
count - amount of elements in the array
Remove the last element of the array Only allowed when the size is larger than zero.
Swap the content of two arrays
rhs - reference to array to swap content with
map a function on all values
fn - function that will be called for each element
ctx - user defined context that will be passed in with each callback