|
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. | |
| Array (IArena &arena) | |
| Initialize empty array with arena. | |
| size_t | capacity () const |
| Get maximum number of elements. If array has arena, capacity can be grown. | |
| size_t | size () const |
| Get number of elements. | |
| bool | is_empty () const |
| Check if size is zero. | |
| T * | data () |
| Get pointer to first element. | |
| const T * | data () const |
| Get pointer to first element. | |
| T & | operator[] (size_t index) |
| Get element at given position. | |
| const T & | operator[] (size_t index) const |
| Get element at given position. | |
| ROC_ATTR_NODISCARD bool | push_back (const T &value) |
| Append element to array. | |
| ROC_ATTR_NODISCARD bool | resize (size_t sz) |
| Set array size. | |
| void | clear () |
| Set array size to zero. | |
| ROC_ATTR_NODISCARD bool | grow (size_t max_sz) |
| Increase array capacity. | |
| ROC_ATTR_NODISCARD bool | grow_exp (size_t min_size) |
| Increase array capacity exponentially. | |
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 |
|
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 |