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

STL-compatible allocator for capability-based memory regions. More...

Classes

struct  rebind
 Rebind the allocator to a different type. More...
 

Public Types

using value_type = T
 The type of object to allocate.
 

Public Member Functions

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

Detailed Description

template<typename T, flags< memory_caps > Caps, size_t Alignment = 0>
struct idfxx::caps_allocator< T, Caps, Alignment >

STL-compatible allocator for capability-based memory regions.

Allocates memory from heap regions matching the specified capability flags. Can be used with standard containers to control memory placement.

When Alignment is non-zero, allocations are guaranteed to be aligned to the specified byte boundary. The alignment must be a power of two.

Template Parameters
TThe type of object to allocate.
CapsThe heap capability flags (e.g., memory_caps::dram).
AlignmentAllocation alignment in bytes (0 = default alignment, must be power of two when non-zero).

Definition at line 252 of file memory.hpp.

Member Typedef Documentation

◆ value_type

template<typename T , flags< memory_caps > Caps, size_t Alignment = 0>
using idfxx::caps_allocator< T, Caps, Alignment >::value_type = T

The type of object to allocate.

Definition at line 253 of file memory.hpp.

Constructor & Destructor Documentation

◆ caps_allocator() [1/2]

template<typename T , flags< memory_caps > Caps, size_t Alignment = 0>
idfxx::caps_allocator< T, Caps, Alignment >::caps_allocator ( )
default

Default constructor.

◆ caps_allocator() [2/2]

template<typename T , flags< memory_caps > Caps, size_t Alignment = 0>
template<typename U >
constexpr idfxx::caps_allocator< T, Caps, Alignment >::caps_allocator ( const caps_allocator< U, Caps, Alignment > &  )
inlineconstexprnoexcept

Rebinding copy constructor.

Template Parameters
UThe source allocator's value type.

Definition at line 274 of file memory.hpp.

Member Function Documentation

◆ allocate()

template<typename T , flags< memory_caps > Caps, size_t Alignment = 0>
T * idfxx::caps_allocator< T, Caps, Alignment >::allocate ( size_t  n)
inline

Allocates memory for n objects of type T.

When Alignment is non-zero, the returned pointer is guaranteed to be aligned to Alignment bytes.

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 abort() on failure.
Exceptions
std::bad_allocIf allocation fails and exceptions are enabled.

Definition at line 290 of file memory.hpp.

References idfxx::to_underlying().

◆ deallocate()

template<typename T , flags< memory_caps > Caps, size_t Alignment = 0>
void idfxx::caps_allocator< T, Caps, Alignment >::deallocate ( T p,
size_t   
)
inlinenoexcept

Deallocates memory previously allocated by this allocator.

Parameters
pPointer to the memory to deallocate.

Definition at line 312 of file memory.hpp.


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