Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
roc::core::Array< T, EmbeddedCapacity > Class Template Reference

Dynamic array. More...

#include <array.h>

Inheritance diagram for roc::core::Array< T, EmbeddedCapacity >:
roc::core::NonCopyable< T >

Public Member Functions

 Array ()
 Initialize empty array without allocator.
 
 Array (IAllocator &allocator)
 Initialize empty array.
 
size_t capacity () const
 Get maximum number of elements. If array has allocator, capacity can be grown.
 
size_t size () const
 Get number of elements.
 
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.
 
void push_back (const T &value)
 Append element to array.
 
bool resize (size_t sz)
 Set array size.
 
bool grow (size_t max_sz)
 Increase array capacity.
 
bool grow_exp (size_t min_size)
 Increase array capacity exponentially.
 

Detailed Description

template<class T, size_t EmbeddedCapacity = 0>
class roc::core::Array< T, EmbeddedCapacity >

Dynamic array.

Elements are stored continuously in a memory chunk allocated using IAllocator. 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.

Template Parameters
Tdefines array element type. It should have copy constructor and destructor.
EmbeddedCapacitydefines 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.

Definition at line 38 of file array.h.

Constructor & Destructor Documentation

◆ Array() [1/2]

template<class T , size_t EmbeddedCapacity = 0>
roc::core::Array< T, EmbeddedCapacity >::Array ( )
inline

Initialize empty array without allocator.

Remarks
Array maximum size will be limited to the embedded capacity.

Definition at line 43 of file array.h.

◆ Array() [2/2]

template<class T , size_t EmbeddedCapacity = 0>
roc::core::Array< T, EmbeddedCapacity >::Array ( IAllocator allocator)
inlineexplicit

Initialize empty array.

Definition at line 51 of file array.h.

◆ ~Array()

template<class T , size_t EmbeddedCapacity = 0>
roc::core::Array< T, EmbeddedCapacity >::~Array ( )
inline

Definition at line 58 of file array.h.

Member Function Documentation

◆ capacity()

template<class T , size_t EmbeddedCapacity = 0>
size_t roc::core::Array< T, EmbeddedCapacity >::capacity ( ) const
inline

Get maximum number of elements. If array has allocator, capacity can be grown.

Definition at line 68 of file array.h.

◆ data() [1/2]

template<class T , size_t EmbeddedCapacity = 0>
T * roc::core::Array< T, EmbeddedCapacity >::data ( )
inline

Get pointer to first element.

Remarks
Returns null if the array is empty.

Definition at line 80 of file array.h.

◆ data() [2/2]

template<class T , size_t EmbeddedCapacity = 0>
const T * roc::core::Array< T, EmbeddedCapacity >::data ( ) const
inline

Get pointer to first element.

Remarks
Returns null if the array is empty.

Definition at line 91 of file array.h.

◆ grow()

template<class T , size_t EmbeddedCapacity = 0>
bool roc::core::Array< T, EmbeddedCapacity >::grow ( size_t  max_sz)
inline

Increase array capacity.

Remarks
If max_sz is greater than the current maximum size, a larger memory region is allocated and the array elements are copied there.
Returns
false if the allocation failed

Definition at line 161 of file array.h.

◆ grow_exp()

template<class T , size_t EmbeddedCapacity = 0>
bool roc::core::Array< T, EmbeddedCapacity >::grow_exp ( size_t  min_size)
inline

Increase array capacity exponentially.

Remarks
If min_size is greater than the current maximum size, 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.
Returns
false if the allocation failed

Definition at line 204 of file array.h.

◆ operator[]() [1/2]

template<class T , size_t EmbeddedCapacity = 0>
T & roc::core::Array< T, EmbeddedCapacity >::operator[] ( size_t  index)
inline

Get element at given position.

Definition at line 100 of file array.h.

◆ operator[]() [2/2]

template<class T , size_t EmbeddedCapacity = 0>
const T & roc::core::Array< T, EmbeddedCapacity >::operator[] ( size_t  index) const
inline

Get element at given position.

Definition at line 109 of file array.h.

◆ push_back()

template<class T , size_t EmbeddedCapacity = 0>
void roc::core::Array< T, EmbeddedCapacity >::push_back ( const T &  value)
inline

Append element to array.

Precondition
Array size() should be less than max_size().

Definition at line 120 of file array.h.

◆ resize()

template<class T , size_t EmbeddedCapacity = 0>
bool roc::core::Array< T, EmbeddedCapacity >::resize ( size_t  sz)
inline

Set array size.

Remarks
Calls grow() to ensure that there is enough space in array.
Returns
false if the allocation failed

Definition at line 134 of file array.h.

◆ size()

template<class T , size_t EmbeddedCapacity = 0>
size_t roc::core::Array< T, EmbeddedCapacity >::size ( ) const
inline

Get number of elements.

Definition at line 73 of file array.h.


The documentation for this class was generated from the following file: