idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
idfxx::spiram_allocator< T > Struct Template Reference

STL-compatible allocator for external PSRAM (SPI RAM). More...

Public Types

using value_type = T
 The type of object to allocate.
 

Public Member Functions

 spiram_allocator ()=default
 Default constructor.
 
template<typename U >
constexpr spiram_allocator (const spiram_allocator< U > &) noexcept
 Rebinding copy constructor.
 
T * allocate (size_t n)
 Allocates memory for n objects of type T from external PSRAM.
 
void deallocate (T *p, size_t) noexcept
 Deallocates memory previously allocated by this allocator.
 

Detailed Description

template<typename T>
struct idfxx::spiram_allocator< T >

STL-compatible allocator for external PSRAM (SPI RAM).

This allocator uses the ESP-IDF heap_caps API to allocate memory from external PSRAM. It can be used with standard containers to place large data structures in PSRAM, freeing internal DRAM for performance-critical or DMA-capable allocations.

Template Parameters
TThe type of object to allocate.
Note
Requires a device with external PSRAM and CONFIG_SPIRAM enabled.

Definition at line 142 of file memory.hpp.

Member Typedef Documentation

◆ value_type

template<typename T >
using idfxx::spiram_allocator< T >::value_type = T

The type of object to allocate.

Definition at line 143 of file memory.hpp.

Constructor & Destructor Documentation

◆ spiram_allocator() [1/2]

template<typename T >
idfxx::spiram_allocator< T >::spiram_allocator ( )
default

Default constructor.

◆ spiram_allocator() [2/2]

template<typename T >
template<typename U >
constexpr idfxx::spiram_allocator< T >::spiram_allocator ( const spiram_allocator< U > &  )
inlineconstexprnoexcept

Rebinding copy constructor.

Template Parameters
UThe source allocator's value type.

Definition at line 154 of file memory.hpp.

Member Function Documentation

◆ allocate()

template<typename T >
T * idfxx::spiram_allocator< T >::allocate ( size_t  n)
inline

Allocates memory for n objects of type T from external PSRAM.

Parameters
nThe number of objects to allocate space for.
Returns
A pointer to the allocated memory.
Note
Throws std::bad_alloc only when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig. When exceptions are disabled, calls esp_system_abort() on failure.
Exceptions
std::bad_allocIf allocation fails and exceptions are enabled.

Definition at line 167 of file memory.hpp.

◆ deallocate()

template<typename T >
void idfxx::spiram_allocator< T >::deallocate ( T *  p,
size_t   
)
inlinenoexcept

Deallocates memory previously allocated by this allocator.

Parameters
pPointer to the memory to deallocate.

Definition at line 184 of file memory.hpp.


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