Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
|
Dynamic array. More...
#include <array.h>
Public Member Functions | |
Array () | |
Initialize empty array without arena. More... | |
Array (IArena &arena) | |
Initialize empty array with arena. More... | |
size_t | capacity () const |
Get maximum number of elements. If array has arena, capacity can be grown. 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... | |
ROC_ATTR_NODISCARD bool | push_back (const T &value) |
Append element to array. More... | |
ROC_ATTR_NODISCARD bool | resize (size_t sz) |
Set array size. More... | |
void | clear () |
Set array size to zero. More... | |
ROC_ATTR_NODISCARD bool | grow (size_t max_sz) |
Increase array capacity. More... | |
ROC_ATTR_NODISCARD bool | grow_exp (size_t min_size) |
Increase array capacity exponentially. More... | |
Dynamic array.
Elements are stored continuously in a memory chunk allocated using IArena. Small chunks can be stored directly in Array object, without extra allocation. Array can be resized only by explicitly calling resize(), grow(), or grow_exp(). Elements are copied during resize and old copies are destroyed.
T | defines array element type. It should have copy constructor and destructor. |
EmbeddedCapacity | defines the size of the fixed-size array embedded directly into Array object; it is used instead of dynamic memory if the array size is small enough. |
|
inline |
|
inlineexplicit |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Increase array capacity exponentially.
min_size
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 |