ESP32 PSRAM Library
Public Types | Public Member Functions | List of all members
esp32_psram::VectorPSRAM< T > Class Template Reference

Vector implementation that uses ESP32's PSRAM for storage. More...

#include <VectorPSRAM.h>

Public Types

using allocator_type = typename vector_type::allocator_type
 
using const_iterator = typename vector_type::const_iterator
 
using const_pointer = typename vector_type::const_pointer
 
using const_reference = typename vector_type::const_reference
 
using const_reverse_iterator = typename vector_type::const_reverse_iterator
 
using difference_type = typename vector_type::difference_type
 
using iterator = typename vector_type::iterator
 
using pointer = typename vector_type::pointer
 
using reference = typename vector_type::reference
 
using reverse_iterator = typename vector_type::reverse_iterator
 
using size_type = typename vector_type::size_type
 
using value_type = typename vector_type::value_type
 

Public Member Functions

 VectorPSRAM ()
 Default constructor - creates an empty vector.
 
 VectorPSRAM (const VectorPSRAM &other)
 Copy constructor. More...
 
template<typename InputIt >
 VectorPSRAM (InputIt first, InputIt last)
 Constructs a vector with the contents of the range [first, last) More...
 
 VectorPSRAM (size_type count)
 Constructs a vector with the given number of default-initialized elements. More...
 
 VectorPSRAM (size_type count, const T &value)
 Constructs a vector with the given number of copies of a value. More...
 
 VectorPSRAM (std::initializer_list< T > init)
 Initializer list constructor. More...
 
 VectorPSRAM (VectorPSRAM &&other) noexcept
 Move constructor. More...
 
reference at (size_type pos)
 Access element with bounds checking. More...
 
const_reference at (size_type pos) const
 Access element with bounds checking (const version) More...
 
reference back ()
 Access the last element. More...
 
const_reference back () const
 Access the last element (const version) More...
 
const_iterator begin () const noexcept
 Get const iterator to the beginning. More...
 
iterator begin () noexcept
 Get iterator to the beginning. More...
 
size_type capacity () const noexcept
 Get the number of elements that can be held in current storage. More...
 
const_iterator cbegin () const noexcept
 Get const iterator to the beginning. More...
 
const_iterator cend () const noexcept
 Get const iterator to the end. More...
 
void clear () noexcept
 Clear the contents.
 
const_reverse_iterator crbegin () const noexcept
 Get const reverse iterator to the beginning. More...
 
const_reverse_iterator crend () const noexcept
 Get const reverse iterator to the end. More...
 
const T * data () const noexcept
 Get pointer to the underlying array (const version) More...
 
T * data () noexcept
 Get pointer to the underlying array. More...
 
template<typename... Args>
iterator emplace (const_iterator pos, Args &&... args)
 Construct an element in-place. More...
 
template<typename... Args>
reference emplace_back (Args &&... args)
 Construct an element in-place at the end. More...
 
bool empty () const noexcept
 Check if the vector is empty. More...
 
const_iterator end () const noexcept
 Get const iterator to the end. More...
 
iterator end () noexcept
 Get iterator to the end. More...
 
iterator erase (const_iterator first, const_iterator last)
 Erase a range of elements. More...
 
iterator erase (const_iterator pos)
 Erase an element. More...
 
reference front ()
 Access the first element. More...
 
const_reference front () const
 Access the first element (const version) More...
 
iterator insert (const_iterator pos, const T &value)
 Insert an element. More...
 
template<typename InputIt >
iterator insert (const_iterator pos, InputIt first, InputIt last)
 Insert elements from a range. More...
 
iterator insert (const_iterator pos, size_type count, const T &value)
 Insert multiple copies of an element. More...
 
iterator insert (const_iterator pos, std::initializer_list< T > ilist)
 Insert elements from an initializer list. More...
 
iterator insert (const_iterator pos, T &&value)
 Insert an element by moving it. More...
 
size_type max_size () const noexcept
 Get the maximum possible number of elements. More...
 
VectorPSRAMoperator= (const VectorPSRAM &other)
 Copy assignment operator. More...
 
VectorPSRAMoperator= (std::initializer_list< T > ilist)
 Initializer list assignment operator. More...
 
VectorPSRAMoperator= (VectorPSRAM &&other) noexcept
 Move assignment operator. More...
 
reference operator[] (size_type pos)
 Access element without bounds checking. More...
 
const_reference operator[] (size_type pos) const
 Access element without bounds checking (const version) More...
 
void pop_back ()
 Remove the last element.
 
void push_back (const T &value)
 Add an element to the end. More...
 
void push_back (T &&value)
 Add an element to the end by moving it. More...
 
const_reverse_iterator rbegin () const noexcept
 Get const reverse iterator to the beginning. More...
 
reverse_iterator rbegin () noexcept
 Get reverse iterator to the beginning. More...
 
const_reverse_iterator rend () const noexcept
 Get const reverse iterator to the end. More...
 
reverse_iterator rend () noexcept
 Get reverse iterator to the end. More...
 
void reserve (size_type new_cap)
 Reserve storage. More...
 
void resize (size_type count)
 Change the number of elements stored. More...
 
void resize (size_type count, const value_type &value)
 Change the number of elements stored. More...
 
void shrink_to_fit ()
 Reduce memory usage by freeing unused memory.
 
size_type size () const noexcept
 Get the number of elements. More...
 
void swap (VectorPSRAM &other) noexcept
 Swap the contents. More...
 

Detailed Description

template<typename T>
class esp32_psram::VectorPSRAM< T >

Vector implementation that uses ESP32's PSRAM for storage.

Template Parameters
TType of elements stored in the vector

This class provides an interface identical to std::vector but allocates all memory in ESP32's PSRAM, which helps preserve the limited internal RAM. It wraps std::vector with a custom allocator that uses PSRAM.

Constructor & Destructor Documentation

◆ VectorPSRAM() [1/6]

template<typename T >
esp32_psram::VectorPSRAM< T >::VectorPSRAM ( size_type  count)
inlineexplicit

Constructs a vector with the given number of default-initialized elements.

Parameters
countThe size of the vector

◆ VectorPSRAM() [2/6]

template<typename T >
esp32_psram::VectorPSRAM< T >::VectorPSRAM ( size_type  count,
const T &  value 
)
inline

Constructs a vector with the given number of copies of a value.

Parameters
countThe size of the vector
valueThe value to initialize elements with

◆ VectorPSRAM() [3/6]

template<typename T >
template<typename InputIt >
esp32_psram::VectorPSRAM< T >::VectorPSRAM ( InputIt  first,
InputIt  last 
)
inline

Constructs a vector with the contents of the range [first, last)

Template Parameters
InputItInput iterator type
Parameters
firstIterator to the first element in the range
lastIterator to one past the last element in the range

◆ VectorPSRAM() [4/6]

template<typename T >
esp32_psram::VectorPSRAM< T >::VectorPSRAM ( const VectorPSRAM< T > &  other)
inline

Copy constructor.

Parameters
otherThe vector to copy from

◆ VectorPSRAM() [5/6]

template<typename T >
esp32_psram::VectorPSRAM< T >::VectorPSRAM ( VectorPSRAM< T > &&  other)
inlinenoexcept

Move constructor.

Parameters
otherThe vector to move from

◆ VectorPSRAM() [6/6]

template<typename T >
esp32_psram::VectorPSRAM< T >::VectorPSRAM ( std::initializer_list< T >  init)
inline

Initializer list constructor.

Parameters
initThe initializer list to copy from

Member Function Documentation

◆ at() [1/2]

template<typename T >
reference esp32_psram::VectorPSRAM< T >::at ( size_type  pos)
inline

Access element with bounds checking.

Parameters
posThe position of the element
Returns
Reference to the element at position pos
Exceptions
std::out_of_rangeif pos is not within the range of the vector

◆ at() [2/2]

template<typename T >
const_reference esp32_psram::VectorPSRAM< T >::at ( size_type  pos) const
inline

Access element with bounds checking (const version)

Parameters
posThe position of the element
Returns
Const reference to the element at position pos
Exceptions
std::out_of_rangeif pos is not within the range of the vector

◆ back() [1/2]

template<typename T >
reference esp32_psram::VectorPSRAM< T >::back ( )
inline

Access the last element.

Returns
Reference to the last element

◆ back() [2/2]

template<typename T >
const_reference esp32_psram::VectorPSRAM< T >::back ( ) const
inline

Access the last element (const version)

Returns
Const reference to the last element

◆ begin() [1/2]

template<typename T >
const_iterator esp32_psram::VectorPSRAM< T >::begin ( ) const
inlinenoexcept

Get const iterator to the beginning.

Returns
Const iterator to the first element

◆ begin() [2/2]

template<typename T >
iterator esp32_psram::VectorPSRAM< T >::begin ( )
inlinenoexcept

Get iterator to the beginning.

Returns
Iterator to the first element

◆ capacity()

template<typename T >
size_type esp32_psram::VectorPSRAM< T >::capacity ( ) const
inlinenoexcept

Get the number of elements that can be held in current storage.

Returns
The capacity of the vector

◆ cbegin()

template<typename T >
const_iterator esp32_psram::VectorPSRAM< T >::cbegin ( ) const
inlinenoexcept

Get const iterator to the beginning.

Returns
Const iterator to the first element

◆ cend()

template<typename T >
const_iterator esp32_psram::VectorPSRAM< T >::cend ( ) const
inlinenoexcept

Get const iterator to the end.

Returns
Const iterator to one past the last element

◆ crbegin()

template<typename T >
const_reverse_iterator esp32_psram::VectorPSRAM< T >::crbegin ( ) const
inlinenoexcept

Get const reverse iterator to the beginning.

Returns
Const reverse iterator to the first element

◆ crend()

template<typename T >
const_reverse_iterator esp32_psram::VectorPSRAM< T >::crend ( ) const
inlinenoexcept

Get const reverse iterator to the end.

Returns
Const reverse iterator to one past the last element

◆ data() [1/2]

template<typename T >
const T* esp32_psram::VectorPSRAM< T >::data ( ) const
inlinenoexcept

Get pointer to the underlying array (const version)

Returns
Const pointer to the underlying array

◆ data() [2/2]

template<typename T >
T* esp32_psram::VectorPSRAM< T >::data ( )
inlinenoexcept

Get pointer to the underlying array.

Returns
Pointer to the underlying array

◆ emplace()

template<typename T >
template<typename... Args>
iterator esp32_psram::VectorPSRAM< T >::emplace ( const_iterator  pos,
Args &&...  args 
)
inline

Construct an element in-place.

Template Parameters
ArgsTypes of arguments to forward to the constructor
Parameters
posIterator to the position before which the element will be constructed
argsArguments to forward to the constructor
Returns
Iterator to the inserted element

◆ emplace_back()

template<typename T >
template<typename... Args>
reference esp32_psram::VectorPSRAM< T >::emplace_back ( Args &&...  args)
inline

Construct an element in-place at the end.

Template Parameters
ArgsTypes of arguments to forward to the constructor
Parameters
argsArguments to forward to the constructor
Returns
Reference to the inserted element

◆ empty()

template<typename T >
bool esp32_psram::VectorPSRAM< T >::empty ( ) const
inlinenoexcept

Check if the vector is empty.

Returns
true if the vector is empty, false otherwise

◆ end() [1/2]

template<typename T >
const_iterator esp32_psram::VectorPSRAM< T >::end ( ) const
inlinenoexcept

Get const iterator to the end.

Returns
Const iterator to one past the last element

◆ end() [2/2]

template<typename T >
iterator esp32_psram::VectorPSRAM< T >::end ( )
inlinenoexcept

Get iterator to the end.

Returns
Iterator to one past the last element

◆ erase() [1/2]

template<typename T >
iterator esp32_psram::VectorPSRAM< T >::erase ( const_iterator  first,
const_iterator  last 
)
inline

Erase a range of elements.

Parameters
firstIterator to the first element to erase
lastIterator to one past the last element to erase
Returns
Iterator to the element after the erased range

◆ erase() [2/2]

template<typename T >
iterator esp32_psram::VectorPSRAM< T >::erase ( const_iterator  pos)
inline

Erase an element.

Parameters
posIterator to the element to erase
Returns
Iterator to the element after the erased element

◆ front() [1/2]

template<typename T >
reference esp32_psram::VectorPSRAM< T >::front ( )
inline

Access the first element.

Returns
Reference to the first element

◆ front() [2/2]

template<typename T >
const_reference esp32_psram::VectorPSRAM< T >::front ( ) const
inline

Access the first element (const version)

Returns
Const reference to the first element

◆ insert() [1/5]

template<typename T >
iterator esp32_psram::VectorPSRAM< T >::insert ( const_iterator  pos,
const T &  value 
)
inline

Insert an element.

Parameters
posIterator to the position before which the element will be inserted
valueThe value to insert
Returns
Iterator to the inserted element

◆ insert() [2/5]

template<typename T >
template<typename InputIt >
iterator esp32_psram::VectorPSRAM< T >::insert ( const_iterator  pos,
InputIt  first,
InputIt  last 
)
inline

Insert elements from a range.

Template Parameters
InputItInput iterator type
Parameters
posIterator to the position before which the elements will be inserted
firstIterator to the first element in the range
lastIterator to one past the last element in the range
Returns
Iterator to the first inserted element

◆ insert() [3/5]

template<typename T >
iterator esp32_psram::VectorPSRAM< T >::insert ( const_iterator  pos,
size_type  count,
const T &  value 
)
inline

Insert multiple copies of an element.

Parameters
posIterator to the position before which the elements will be inserted
countNumber of copies to insert
valueThe value to insert
Returns
Iterator to the first inserted element

◆ insert() [4/5]

template<typename T >
iterator esp32_psram::VectorPSRAM< T >::insert ( const_iterator  pos,
std::initializer_list< T >  ilist 
)
inline

Insert elements from an initializer list.

Parameters
posIterator to the position before which the elements will be inserted
ilistThe initializer list to insert from
Returns
Iterator to the first inserted element

◆ insert() [5/5]

template<typename T >
iterator esp32_psram::VectorPSRAM< T >::insert ( const_iterator  pos,
T &&  value 
)
inline

Insert an element by moving it.

Parameters
posIterator to the position before which the element will be inserted
valueThe value to insert
Returns
Iterator to the inserted element

◆ max_size()

template<typename T >
size_type esp32_psram::VectorPSRAM< T >::max_size ( ) const
inlinenoexcept

Get the maximum possible number of elements.

Returns
The maximum possible number of elements the vector can hold

◆ operator=() [1/3]

template<typename T >
VectorPSRAM& esp32_psram::VectorPSRAM< T >::operator= ( const VectorPSRAM< T > &  other)
inline

Copy assignment operator.

Parameters
otherThe vector to copy from
Returns
Reference to this vector

◆ operator=() [2/3]

template<typename T >
VectorPSRAM& esp32_psram::VectorPSRAM< T >::operator= ( std::initializer_list< T >  ilist)
inline

Initializer list assignment operator.

Parameters
ilistThe initializer list to copy from
Returns
Reference to this vector

◆ operator=() [3/3]

template<typename T >
VectorPSRAM& esp32_psram::VectorPSRAM< T >::operator= ( VectorPSRAM< T > &&  other)
inlinenoexcept

Move assignment operator.

Parameters
otherThe vector to move from
Returns
Reference to this vector

◆ operator[]() [1/2]

template<typename T >
reference esp32_psram::VectorPSRAM< T >::operator[] ( size_type  pos)
inline

Access element without bounds checking.

Parameters
posThe position of the element
Returns
Reference to the element at position pos

◆ operator[]() [2/2]

template<typename T >
const_reference esp32_psram::VectorPSRAM< T >::operator[] ( size_type  pos) const
inline

Access element without bounds checking (const version)

Parameters
posThe position of the element
Returns
Const reference to the element at position pos

◆ push_back() [1/2]

template<typename T >
void esp32_psram::VectorPSRAM< T >::push_back ( const T &  value)
inline

Add an element to the end.

Parameters
valueThe value to append

◆ push_back() [2/2]

template<typename T >
void esp32_psram::VectorPSRAM< T >::push_back ( T &&  value)
inline

Add an element to the end by moving it.

Parameters
valueThe value to append

◆ rbegin() [1/2]

template<typename T >
const_reverse_iterator esp32_psram::VectorPSRAM< T >::rbegin ( ) const
inlinenoexcept

Get const reverse iterator to the beginning.

Returns
Const reverse iterator to the first element

◆ rbegin() [2/2]

template<typename T >
reverse_iterator esp32_psram::VectorPSRAM< T >::rbegin ( )
inlinenoexcept

Get reverse iterator to the beginning.

Returns
Reverse iterator to the first element

◆ rend() [1/2]

template<typename T >
const_reverse_iterator esp32_psram::VectorPSRAM< T >::rend ( ) const
inlinenoexcept

Get const reverse iterator to the end.

Returns
Const reverse iterator to one past the last element

◆ rend() [2/2]

template<typename T >
reverse_iterator esp32_psram::VectorPSRAM< T >::rend ( )
inlinenoexcept

Get reverse iterator to the end.

Returns
Reverse iterator to one past the last element

◆ reserve()

template<typename T >
void esp32_psram::VectorPSRAM< T >::reserve ( size_type  new_cap)
inline

Reserve storage.

Parameters
new_capThe new capacity of the vector
Exceptions
std::length_errorif new_cap > max_size()

◆ resize() [1/2]

template<typename T >
void esp32_psram::VectorPSRAM< T >::resize ( size_type  count)
inline

Change the number of elements stored.

Parameters
countThe new size of the vector

◆ resize() [2/2]

template<typename T >
void esp32_psram::VectorPSRAM< T >::resize ( size_type  count,
const value_type &  value 
)
inline

Change the number of elements stored.

Parameters
countThe new size of the vector
valueThe value to initialize new elements with

◆ size()

template<typename T >
size_type esp32_psram::VectorPSRAM< T >::size ( ) const
inlinenoexcept

Get the number of elements.

Returns
The number of elements in the vector

◆ swap()

template<typename T >
void esp32_psram::VectorPSRAM< T >::swap ( VectorPSRAM< T > &  other)
inlinenoexcept

Swap the contents.

Parameters
otherVector to swap with

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