Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
|
Dynamic array. More...
#include <array.h>
Public Member Functions | |
Array (IArena &arena) | |
Initialize empty array with arena. More... | |
size_t | capacity () const |
Get maximum number of elements that can be added without reallocation. More... | |
size_t | size () const |
Get number of elements. More... | |
bool | is_empty () const |
Check if size is zero. More... | |
T * | data () |
Get pointer to first element. More... | |
const T * | data () const |
Get pointer to first element. More... | |
T & | operator[] (size_t index) |
Get element at given position. More... | |
const T & | operator[] (size_t index) const |
Get element at given position. More... | |
T & | front () |
Get reference to first element. More... | |
const T & | front () const |
Get const reference to first element. More... | |
T & | back () |
Get reference to last element. More... | |
const T & | back () const |
Get const reference to last element. More... | |
ROC_ATTR_NODISCARD bool | push_back (const T &value) |
Append element to array. More... | |
void | pop_back () |
Remove last element from the array. More... | |
ROC_ATTR_NODISCARD bool | resize (size_t new_size) |
Set array size. More... | |
void | clear () |
Set array size to zero. More... | |
ROC_ATTR_NODISCARD bool | grow (size_t min_capacity) |
Increase array capacity. More... | |
ROC_ATTR_NODISCARD bool | grow_exp (size_t min_capacity) |
Increase array capacity exponentially. More... | |
Dynamic array.
Elements are stored continuously in a memory chunk allocated using IArena, or directly in Array object when number of elements is small.
Array supports resizing and inserting and removing elements in the end with amortized O(1) complexity.
T | defines array element type. It should have default constructor, copy constructor, and assignment operator. |
EmbeddedCapacity | defines number of elements in the fixed-size chunk embedded directly into Array object; it is used instead of dynamic memory if the array size is small enough. |
|
inlineexplicit |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Increase array capacity exponentially.
min_capacity
is greater than the current capacity, a larger memory region is allocated and the array elements are copied there. The size growth will follow the sequence: 0, 2, 4, 8, 16, ... until it reaches some threshold, and then starts growing linearly.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |