|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
Memory capability flags, heap queries, allocation, walking, integrity checking, and STL-compatible allocators. More...
Namespaces | |
| namespace | idfxx |
| namespace | idfxx::memory |
Classes | |
| struct | idfxx::memory::info |
| Heap region statistics. More... | |
| struct | idfxx::memory::region |
| Information about a heap region, passed to walk callbacks. More... | |
| struct | idfxx::memory::block |
| Information about a single heap block, passed to walk callbacks. More... | |
| struct | idfxx::caps_allocator< T, Caps, Alignment > |
| STL-compatible allocator for capability-based memory regions. More... | |
Typedefs | |
| template<typename T > | |
| using | idfxx::dram_allocator = caps_allocator< T, memory::caps::dram > |
| STL-compatible allocator for internal DRAM. | |
| template<typename T > | |
| using | idfxx::spiram_allocator = caps_allocator< T, memory::caps::spiram > |
| STL-compatible allocator for external PSRAM (SPI RAM). | |
| template<typename T > | |
| using | idfxx::dma_allocator = caps_allocator< T, memory::caps::dma > |
| STL-compatible allocator for DMA-capable memory. | |
| template<typename T , size_t Alignment> | |
| using | idfxx::aligned_dram_allocator = caps_allocator< T, memory::caps::dram, Alignment > |
| STL-compatible aligned allocator for internal DRAM. | |
| template<typename T , size_t Alignment> | |
| using | idfxx::aligned_spiram_allocator = caps_allocator< T, memory::caps::spiram, Alignment > |
| STL-compatible aligned allocator for external PSRAM (SPI RAM). | |
| template<typename T , size_t Alignment> | |
| using | idfxx::aligned_dma_allocator = caps_allocator< T, memory::caps::dma, Alignment > |
| STL-compatible aligned allocator for DMA-capable memory. | |
Enumerations | |
| enum class | idfxx::memory::caps : uint32_t { idfxx::memory::caps::access_32bit = MALLOC_CAP_32BIT , idfxx::memory::caps::access_8bit = MALLOC_CAP_8BIT , idfxx::memory::caps::dma = MALLOC_CAP_DMA , idfxx::memory::caps::spiram = MALLOC_CAP_SPIRAM , idfxx::memory::caps::internal = MALLOC_CAP_INTERNAL , idfxx::memory::caps::default_heap = MALLOC_CAP_DEFAULT , idfxx::memory::caps::iram = MALLOC_CAP_IRAM_8BIT , idfxx::memory::caps::retention = MALLOC_CAP_RETENTION , idfxx::memory::caps::rtc = MALLOC_CAP_RTCRAM , idfxx::memory::caps::dma_desc_ahb = MALLOC_CAP_DMA_DESC_AHB , idfxx::memory::caps::dma_desc_axi = MALLOC_CAP_DMA_DESC_AXI , idfxx::memory::caps::cache_aligned = MALLOC_CAP_CACHE_ALIGNED , idfxx::memory::caps::dram = internal | access_8bit } |
| Memory capability flags for heap allocations. More... | |
Functions | |
| size_t | idfxx::memory::total_size (flags< caps > c) noexcept |
| Returns the total size of heap regions matching the given capabilities. | |
| size_t | idfxx::memory::free_size (flags< caps > c) noexcept |
| Returns the current free size of heap regions matching the given capabilities. | |
| size_t | idfxx::memory::largest_free_block (flags< caps > c) noexcept |
| Returns the largest free block in heap regions matching the given capabilities. | |
| size_t | idfxx::memory::minimum_free_size (flags< caps > c) noexcept |
| Returns the minimum free size since boot for heap regions matching the given capabilities. | |
| info | idfxx::memory::get_info (flags< caps > c) noexcept |
| Returns detailed heap statistics for regions matching the given capabilities. | |
| template<typename F > | |
| void | idfxx::memory::walk (flags< caps > c, F &&walker) |
| Walk all heap blocks in regions matching the given capabilities. | |
| template<typename F > | |
| void | idfxx::memory::walk (F &&walker) |
| Walk all heap blocks across all heaps. | |
| bool | idfxx::memory::check_integrity (flags< caps > c, bool print_errors=false) noexcept |
| Check integrity of heaps with the given capabilities, or all heaps. | |
| bool | idfxx::memory::check_integrity (bool print_errors=false) noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| void | idfxx::memory::dump (flags< caps > c) noexcept |
| Dump the structure of heaps with matching capabilities, or all heaps. | |
| void | idfxx::memory::dump () noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| void * | idfxx::malloc (size_t size, flags< memory::caps > c) noexcept |
| Allocates memory from heap regions matching the given capabilities. | |
| void * | idfxx::calloc (size_t n, size_t size, flags< memory::caps > c) noexcept |
| Allocates zero-initialized memory from heap regions matching the given capabilities. | |
| void * | idfxx::realloc (void *ptr, size_t size, flags< memory::caps > c) noexcept |
| Reallocates memory from heap regions matching the given capabilities. | |
| void | idfxx::free (void *ptr) noexcept |
| Frees memory previously allocated by heap allocation functions. | |
| void * | idfxx::aligned_alloc (size_t alignment, size_t size, flags< memory::caps > c) noexcept |
| Allocates aligned memory from heap regions matching the given capabilities. | |
| void * | idfxx::aligned_calloc (size_t alignment, size_t n, size_t size, flags< memory::caps > c) noexcept |
| Allocates aligned, zero-initialized memory from heap regions matching the given capabilities. | |
| template<typename T , typename U , flags< memory::caps > Caps, size_t Alignment> | |
| constexpr bool | idfxx::operator== (const caps_allocator< T, Caps, Alignment > &, const caps_allocator< U, Caps, Alignment > &) noexcept |
| Equality comparison for caps_allocator. | |
Variables | |
| size_t | idfxx::memory::info::total_free_bytes |
| Total free bytes across matching regions. | |
| size_t | idfxx::memory::info::total_allocated_bytes |
| Total allocated bytes across matching regions. | |
| size_t | idfxx::memory::info::largest_free_block |
| Size of the largest contiguous free block. | |
| size_t | idfxx::memory::info::minimum_free_bytes |
| Minimum free bytes since boot (high-water mark). | |
| size_t | idfxx::memory::info::allocated_blocks |
| Number of allocated blocks. | |
| size_t | idfxx::memory::info::free_blocks |
| Number of free blocks. | |
| size_t | idfxx::memory::info::total_blocks |
| Total number of blocks (allocated + free). | |
| intptr_t | idfxx::memory::region::start |
| Start address of the heap region. | |
| intptr_t | idfxx::memory::region::end |
| End address of the heap region. | |
| void * | idfxx::memory::block::ptr |
| Pointer to the block data. | |
| size_t | idfxx::memory::block::size |
| Size of the block in bytes. | |
| bool | idfxx::memory::block::used |
| True if allocated, false if free. | |
Memory capability flags, heap queries, allocation, walking, integrity checking, and STL-compatible allocators.
Provides composable memory capability flags via memory::caps, heap query functions, heap walking and integrity checking, and allocators (including aligned variants) for internal DRAM, external PSRAM, and DMA-capable memory that can be used with standard containers.
STL-compatible aligned allocator for DMA-capable memory.
Allocates DMA-capable memory with a guaranteed byte alignment.
| T | The type of object to allocate. |
| Alignment | Alignment in bytes (must be a power of two). |
Definition at line 520 of file memory.hpp.
STL-compatible aligned allocator for internal DRAM.
Allocates from internal DRAM with a guaranteed byte alignment.
| T | The type of object to allocate. |
| Alignment | Alignment in bytes (must be a power of two). |
Definition at line 494 of file memory.hpp.
STL-compatible aligned allocator for external PSRAM (SPI RAM).
Allocates from external PSRAM with a guaranteed byte alignment.
| T | The type of object to allocate. |
| Alignment | Alignment in bytes (must be a power of two). |
CONFIG_SPIRAM enabled. Definition at line 508 of file memory.hpp.
STL-compatible allocator for DMA-capable memory.
Allocates memory that is suitable for DMA transfers. Can be used with standard containers to create buffers for SPI, I2S, LCD, and other DMA-capable peripherals.
| T | The type of object to allocate. |
Definition at line 482 of file memory.hpp.
STL-compatible allocator for internal DRAM.
Allocates memory from internal DRAM with 8-bit access capability. Can be used with standard containers to ensure allocations come from internal memory rather than external PSRAM.
| T | The type of object to allocate. |
Definition at line 454 of file memory.hpp.
STL-compatible allocator for external PSRAM (SPI RAM).
Allocates memory from external PSRAM. Can be used with standard containers to place large data structures in PSRAM, freeing internal DRAM for performance-critical or DMA-capable allocations.
| T | The type of object to allocate. |
CONFIG_SPIRAM enabled. Definition at line 469 of file memory.hpp.
|
strong |
Memory capability flags for heap allocations.
Composable flags that describe properties of memory regions. Use the bitwise operators provided by idfxx::flags<memory::caps> to combine multiple capabilities.
Used by components such as Task Component (for stack allocation) and Queue Component (for queue storage) to control memory placement, and by the heap query functions to filter heap statistics.
spiram requires a device with external PSRAM and CONFIG_SPIRAM enabled. Definition at line 48 of file memory.hpp.
|
inlinenoexcept |
Allocates aligned memory from heap regions matching the given capabilities.
| alignment | Alignment in bytes (must be a power of two). |
| size | Number of bytes to allocate. |
| c | Capability flags to select heap regions. |
nullptr on failure. Definition at line 332 of file memory.hpp.
References idfxx::to_underlying().
|
inlinenoexcept |
Allocates aligned, zero-initialized memory from heap regions matching the given capabilities.
| alignment | Alignment in bytes (must be a power of two). |
| n | Number of elements to allocate. |
| size | Size of each element in bytes. |
| c | Capability flags to select heap regions. |
nullptr on failure. Definition at line 346 of file memory.hpp.
References idfxx::to_underlying().
|
inlinenoexcept |
Allocates zero-initialized memory from heap regions matching the given capabilities.
| n | Number of elements to allocate. |
| size | Size of each element in bytes. |
| c | Capability flags to select heap regions. |
nullptr on failure. Definition at line 291 of file memory.hpp.
References idfxx::to_underlying().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 240 of file memory.hpp.
Check integrity of heaps with the given capabilities, or all heaps.
When called without arguments, checks all heaps.
| c | Capability flags to filter heap regions. |
| print_errors | Print specific errors if heap corruption is found. |
Definition at line 235 of file memory.hpp.
References idfxx::to_underlying().
|
inlinenoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 260 of file memory.hpp.
Dump the structure of heaps with matching capabilities, or all heaps.
Prints detailed information about every block in matching heaps to the serial console. When called without arguments, dumps all heaps.
| c | Capability flags to filter heap regions. |
Definition at line 255 of file memory.hpp.
References idfxx::to_underlying().
Frees memory previously allocated by heap allocation functions.
Accepts nullptr safely. Works for both regular and aligned allocations.
| ptr | Pointer to the memory to free, or nullptr. |
Definition at line 319 of file memory.hpp.
Returns the current free size of heap regions matching the given capabilities.
| c | Capability flags to filter heap regions. |
Definition at line 112 of file memory.hpp.
References idfxx::to_underlying().
Returns detailed heap statistics for regions matching the given capabilities.
| c | Capability flags to filter heap regions. |
Definition at line 148 of file memory.hpp.
References idfxx::to_underlying().
Returns the largest free block in heap regions matching the given capabilities.
| c | Capability flags to filter heap regions. |
Definition at line 123 of file memory.hpp.
References idfxx::to_underlying().
|
inlinenoexcept |
Allocates memory from heap regions matching the given capabilities.
| size | Number of bytes to allocate. |
| c | Capability flags to select heap regions. |
nullptr on failure. Definition at line 278 of file memory.hpp.
References idfxx::to_underlying().
Returns the minimum free size since boot for heap regions matching the given capabilities.
This is the high-water mark of heap usage — the lowest amount of free memory recorded since the system booted.
| c | Capability flags to filter heap regions. |
Definition at line 137 of file memory.hpp.
References idfxx::to_underlying().
|
constexprnoexcept |
Equality comparison for caps_allocator.
All caps_allocator instances with the same capability flags and alignment are considered equal.
Definition at line 439 of file memory.hpp.
|
inlinenoexcept |
Reallocates memory from heap regions matching the given capabilities.
If ptr is nullptr, behaves like malloc(). The returned pointer may differ from ptr.
| ptr | Pointer to previously allocated memory, or nullptr. |
| size | New size in bytes. |
| c | Capability flags to select heap regions. |
nullptr on failure. Definition at line 307 of file memory.hpp.
References idfxx::to_underlying().
Returns the total size of heap regions matching the given capabilities.
| c | Capability flags to filter heap regions. |
Definition at line 101 of file memory.hpp.
References idfxx::to_underlying().
Walk all heap blocks across all heaps.
Iterates over every block in all registered heaps, invoking walker for each block.
| F | Callable with signature bool(region, block). |
| walker | Callable invoked for each block. Return true to continue, false to stop. |
Definition at line 215 of file memory.hpp.
References idfxx::memory::block::ptr, and idfxx::memory::region::start.
Walk all heap blocks in regions matching the given capabilities.
Iterates over every block in heaps that match c, invoking walker for each block. The walker receives a region describing the containing region and a block describing the individual block.
| F | Callable with signature bool(region, block). |
| c | Capability flags to filter heap regions. |
| walker | Callable invoked for each block. Return true to continue, false to stop. |
Definition at line 196 of file memory.hpp.
References idfxx::memory::block::ptr, idfxx::memory::region::start, and idfxx::to_underlying().
| size_t idfxx::memory::info::allocated_blocks |
Number of allocated blocks.
Definition at line 89 of file memory.hpp.
| intptr_t idfxx::memory::region::end |
End address of the heap region.
Definition at line 170 of file memory.hpp.
| size_t idfxx::memory::info::free_blocks |
Number of free blocks.
Definition at line 90 of file memory.hpp.
| size_t idfxx::memory::info::largest_free_block |
Size of the largest contiguous free block.
Definition at line 87 of file memory.hpp.
| size_t idfxx::memory::info::minimum_free_bytes |
Minimum free bytes since boot (high-water mark).
Definition at line 88 of file memory.hpp.
| void* idfxx::memory::block::ptr |
Pointer to the block data.
Definition at line 178 of file memory.hpp.
Referenced by idfxx::memory::walk(), and idfxx::memory::walk().
| size_t idfxx::memory::block::size |
Size of the block in bytes.
Definition at line 179 of file memory.hpp.
| intptr_t idfxx::memory::region::start |
Start address of the heap region.
Definition at line 169 of file memory.hpp.
Referenced by idfxx::memory::walk(), and idfxx::memory::walk().
| size_t idfxx::memory::info::total_allocated_bytes |
Total allocated bytes across matching regions.
Definition at line 86 of file memory.hpp.
| size_t idfxx::memory::info::total_blocks |
Total number of blocks (allocated + free).
Definition at line 91 of file memory.hpp.
| size_t idfxx::memory::info::total_free_bytes |
Total free bytes across matching regions.
Definition at line 85 of file memory.hpp.
| bool idfxx::memory::block::used |
True if allocated, false if free.
Definition at line 180 of file memory.hpp.