28#include <esp_heap_caps.h>
49#ifdef CONFIG_HEAP_HAS_EXEC_HEAP
152 .total_free_bytes = raw.total_free_bytes,
153 .total_allocated_bytes = raw.total_allocated_bytes,
154 .largest_free_block = raw.largest_free_block,
155 .minimum_free_bytes = raw.minimum_free_bytes,
156 .allocated_blocks = raw.allocated_blocks,
157 .free_blocks = raw.free_blocks,
158 .total_blocks = raw.total_blocks,
198 auto&
fn = *
static_cast<std::remove_reference_t<F>*
>(
user_data);
217 auto&
fn = *
static_cast<std::remove_reference_t<F>*
>(
user_data);
319inline void free(
void* ptr)
noexcept {
366template<
typename T, flags<memory::caps> Caps,
size_t Alignment = 0>
406 if (
n > std::numeric_limits<size_t>::max() /
sizeof(
T)) {
413 static_assert((
Alignment & (
Alignment - 1)) == 0,
"Alignment must be a power of two");
419 return static_cast<T*
>(
p);
437template<
typename T,
typename U, flags<memory::caps> Caps,
size_t Alignment>
493template<
typename T,
size_t Alignment>
507template<
typename T,
size_t Alignment>
519template<
typename T,
size_t Alignment>
Type-safe bitflags from scoped enums.
size_t total_size(flags< caps > c) noexcept
Returns the total size of heap regions matching the given capabilities.
void free(void *ptr) noexcept
Frees memory previously allocated by heap allocation functions.
void * realloc(void *ptr, size_t size, flags< memory::caps > c) noexcept
Reallocates memory from heap regions matching the given capabilities.
void walk(flags< caps > c, F &&walker)
Walk all heap blocks in regions matching the given capabilities.
size_t largest_free_block
Size of the largest contiguous free block.
void * malloc(size_t size, flags< memory::caps > c) noexcept
Allocates memory from heap regions matching the given capabilities.
constexpr bool operator==(const caps_allocator< T, Caps, Alignment > &, const caps_allocator< U, Caps, Alignment > &) noexcept
Equality comparison for caps_allocator.
size_t largest_free_block(flags< caps > c) noexcept
Returns the largest free block in heap regions matching the given capabilities.
void * ptr
Pointer to the block data.
intptr_t end
End address of the heap region.
size_t total_blocks
Total number of blocks (allocated + free).
size_t free_blocks
Number of free blocks.
bool used
True if allocated, false if free.
caps_allocator< T, memory::caps::dma > dma_allocator
STL-compatible allocator for DMA-capable memory.
info get_info(flags< caps > c) noexcept
Returns detailed heap statistics for regions matching the given capabilities.
caps_allocator< T, memory::caps::dma, Alignment > aligned_dma_allocator
STL-compatible aligned allocator for DMA-capable memory.
size_t total_allocated_bytes
Total allocated bytes across matching regions.
caps
Memory capability flags for heap allocations.
bool check_integrity(flags< caps > c, bool print_errors=false) noexcept
Check integrity of heaps with the given capabilities, or all heaps.
void * aligned_alloc(size_t alignment, size_t size, flags< memory::caps > c) noexcept
Allocates aligned memory from heap regions matching the given capabilities.
size_t size
Size of the block in bytes.
void * calloc(size_t n, size_t size, flags< memory::caps > c) noexcept
Allocates zero-initialized memory from heap regions matching the given capabilities.
size_t free_size(flags< caps > c) noexcept
Returns the current free size of heap regions matching the given capabilities.
intptr_t start
Start address of the heap region.
size_t total_free_bytes
Total free bytes across matching regions.
size_t allocated_blocks
Number of allocated blocks.
caps_allocator< T, memory::caps::spiram, Alignment > aligned_spiram_allocator
STL-compatible aligned allocator for external PSRAM (SPI RAM).
size_t minimum_free_bytes
Minimum free bytes since boot (high-water mark).
size_t minimum_free_size(flags< caps > c) noexcept
Returns the minimum free size since boot for heap regions matching the given capabilities.
caps_allocator< T, memory::caps::spiram > spiram_allocator
STL-compatible allocator for external PSRAM (SPI RAM).
void dump() noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
void * 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.
caps_allocator< T, memory::caps::dram, Alignment > aligned_dram_allocator
STL-compatible aligned allocator for internal DRAM.
caps_allocator< T, memory::caps::dram > dram_allocator
STL-compatible allocator for internal DRAM.
@ cache_aligned
Cache-line aligned.
@ iram
IRAM with unaligned access.
@ dma_desc_ahb
AHB DMA descriptor capable.
@ default_heap
Default heap (same as malloc)
@ dma_desc_axi
AXI DMA descriptor capable.
@ retention
Retention DMA accessible.
@ access_32bit
32-bit aligned access
@ internal
Internal memory.
@ access_8bit
8/16/32-bit access
@ dram
Internal DRAM (8-bit accessible)
std::expected< T, std::error_code > result
result type wrapping a value or error code.
constexpr auto to_underlying(flags< E > f) noexcept
Returns the underlying integral value of a flags object.
Rebind the allocator to a different type.
caps_allocator< U, Caps, Alignment > other
The rebound allocator type.
STL-compatible allocator for capability-based memory regions.
caps_allocator()=default
Default constructor.
T * allocate(size_t n)
Allocates memory for n objects of type T.
T value_type
The type of object to allocate.
void deallocate(T *p, size_t) noexcept
Deallocates memory previously allocated by this allocator.
constexpr caps_allocator(const caps_allocator< U, Caps, Alignment > &) noexcept
Rebinding copy constructor.
Information about a single heap block, passed to walk callbacks.
Information about a heap region, passed to walk callbacks.