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 {
367template<
typename T, flags<memory::capabilities> Caps,
size_t Alignment = 0>
407 if (
n > std::numeric_limits<size_t>::max() /
sizeof(
T)) {
414 static_assert((
Alignment & (
Alignment - 1)) == 0,
"Alignment must be a power of two");
420 return static_cast<T*
>(
p);
438template<
typename T,
typename U, flags<memory::capabilities> 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.
allocator< T, memory::capabilities::spiram > spiram_allocator
STL-compatible allocator for external PSRAM (SPI RAM).
void free(void *ptr) noexcept
Frees memory previously allocated by heap allocation functions.
size_t total_size(flags< capabilities > c) noexcept
Returns the total size of heap regions matching the given capabilities.
void * aligned_calloc(size_t alignment, size_t n, size_t size, flags< memory::capabilities > c) noexcept
Allocates aligned, zero-initialized memory from heap regions matching the given capabilities.
void * realloc(void *ptr, size_t size, flags< memory::capabilities > c) noexcept
Reallocates memory from heap regions matching the given capabilities.
capabilities
Memory capability flags for heap allocations.
size_t largest_free_block
Size of the largest contiguous free block.
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.
void * malloc(size_t size, flags< memory::capabilities > c) noexcept
Allocates memory from heap regions matching the given capabilities.
bool used
True if allocated, false if free.
bool check_integrity(flags< capabilities > c, bool print_errors=false) noexcept
Check integrity of heaps with the given capabilities, or all heaps.
size_t total_allocated_bytes
Total allocated bytes across matching regions.
size_t free_size(flags< capabilities > c) noexcept
Returns the current free size of heap regions matching the given capabilities.
size_t size
Size of the block in bytes.
size_t largest_free_block(flags< capabilities > c) noexcept
Returns the largest free block in heap regions matching the given capabilities.
void * calloc(size_t n, size_t size, flags< memory::capabilities > c) noexcept
Allocates zero-initialized memory from heap regions matching the given capabilities.
intptr_t start
Start address of the heap region.
allocator< T, memory::capabilities::spiram, Alignment > aligned_spiram_allocator
STL-compatible aligned allocator for external PSRAM (SPI RAM).
size_t total_free_bytes
Total free bytes across matching regions.
size_t allocated_blocks
Number of allocated blocks.
size_t minimum_free_bytes
Minimum free bytes since boot (high-water mark).
allocator< T, memory::capabilities::dma, Alignment > aligned_dma_allocator
STL-compatible aligned allocator for DMA-capable memory.
allocator< T, memory::capabilities::dma > dma_allocator
STL-compatible allocator for DMA-capable memory.
void * aligned_alloc(size_t alignment, size_t size, flags< memory::capabilities > c) noexcept
Allocates aligned memory from heap regions matching the given capabilities.
allocator< T, memory::capabilities::dram, Alignment > aligned_dram_allocator
STL-compatible aligned allocator for internal DRAM.
constexpr bool operator==(const allocator< T, Caps, Alignment > &, const allocator< U, Caps, Alignment > &) noexcept
Equality comparison for allocator.
allocator< T, memory::capabilities::dram > dram_allocator
STL-compatible allocator for internal DRAM.
size_t minimum_free_size(flags< capabilities > c) noexcept
Returns the minimum free size since boot for heap regions matching the given capabilities.
void dump() noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
void walk(flags< capabilities > c, F &&walker)
Walk all heap blocks in regions matching the given capabilities.
info get_info(flags< capabilities > c) noexcept
Returns detailed heap statistics for regions matching the given capabilities.
@ 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.
allocator< U, Caps, Alignment > other
The rebound allocator type.
STL-compatible allocator for capability-based memory regions.
constexpr allocator(const allocator< U, Caps, Alignment > &) noexcept
Rebinding copy constructor.
void deallocate(T *p, size_t) noexcept
Deallocates memory previously allocated by this allocator.
allocator()=default
Default constructor.
T value_type
The type of object to allocate.
T * allocate(size_t n)
Allocates memory for n objects of type T.
Information about a single heap block, passed to walk callbacks.
Information about a heap region, passed to walk callbacks.