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

Custom allocator that uses ESP32's PSRAM for memory allocation. More...

#include <VectorPSRAM.h>

Classes

struct  rebind
 Rebind allocator to another type. More...
 

Public Types

using const_pointer = const T *
 
using const_reference = const T &
 
using difference_type = std::ptrdiff_t
 
using pointer = T *
 
using reference = T &
 
using size_type = std::size_t
 
using value_type = T
 

Public Member Functions

 PSRAMAllocator () noexcept
 Default constructor.
 
template<typename U >
 PSRAMAllocator (const PSRAMAllocator< U > &) noexcept
 Copy constructor from another allocator type. More...
 
pointer allocate (size_type n)
 Allocate memory from PSRAM. More...
 
void deallocate (pointer p, size_type) noexcept
 Deallocate memory. More...
 

Detailed Description

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

Custom allocator that uses ESP32's PSRAM for memory allocation.

Template Parameters
TType of elements to allocate

This allocator uses ESP32's heap_caps_malloc with MALLOC_CAP_SPIRAM flag to ensure all memory is allocated in PSRAM instead of regular RAM.

Constructor & Destructor Documentation

◆ PSRAMAllocator()

template<typename T >
template<typename U >
esp32_psram::PSRAMAllocator< T >::PSRAMAllocator ( const PSRAMAllocator< U > &  )
inlinenoexcept

Copy constructor from another allocator type.

Template Parameters
UType of the other allocator
Parameters
otherThe other allocator

Member Function Documentation

◆ allocate()

template<typename T >
pointer esp32_psram::PSRAMAllocator< T >::allocate ( size_type  n)
inline

Allocate memory from PSRAM.

Parameters
nNumber of elements to allocate
Returns
Pointer to allocated memory
Exceptions
std::bad_allocIf allocation fails or size is too large

◆ deallocate()

template<typename T >
void esp32_psram::PSRAMAllocator< T >::deallocate ( pointer  p,
size_type   
)
inlinenoexcept

Deallocate memory.

Parameters
pPointer to memory to deallocate
sizeSize of allocation (unused)

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