idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
memory.hpp File Reference

IDFXX memory utilities. More...

#include <idfxx/error.hpp>
#include <idfxx/flags.hpp>
#include <cstddef>
#include <cstdint>
#include <esp_heap_caps.h>
#include <limits>
#include <type_traits>

Go to the source code of this file.

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::allocator< T, Caps, Alignment >
 STL-compatible allocator for capability-based memory regions. More...
 
struct  idfxx::allocator< T, Caps, Alignment >::rebind< U >
 Rebind the allocator to a different type. More...
 

Namespaces

namespace  idfxx
 
namespace  idfxx::memory
 

Typedefs

template<typename T >
using idfxx::dram_allocator = allocator< T, memory::capabilities::dram >
 STL-compatible allocator for internal DRAM.
 
template<typename T >
using idfxx::spiram_allocator = allocator< T, memory::capabilities::spiram >
 STL-compatible allocator for external PSRAM (SPI RAM).
 
template<typename T >
using idfxx::dma_allocator = allocator< T, memory::capabilities::dma >
 STL-compatible allocator for DMA-capable memory.
 
template<typename T , size_t Alignment>
using idfxx::aligned_dram_allocator = allocator< T, memory::capabilities::dram, Alignment >
 STL-compatible aligned allocator for internal DRAM.
 
template<typename T , size_t Alignment>
using idfxx::aligned_spiram_allocator = allocator< T, memory::capabilities::spiram, Alignment >
 STL-compatible aligned allocator for external PSRAM (SPI RAM).
 
template<typename T , size_t Alignment>
using idfxx::aligned_dma_allocator = allocator< T, memory::capabilities::dma, Alignment >
 STL-compatible aligned allocator for DMA-capable memory.
 

Enumerations

enum class  idfxx::memory::capabilities : uint32_t {
  idfxx::memory::capabilities::access_32bit = MALLOC_CAP_32BIT ,
  idfxx::memory::capabilities::access_8bit = MALLOC_CAP_8BIT ,
  idfxx::memory::capabilities::dma = MALLOC_CAP_DMA ,
  idfxx::memory::capabilities::spiram = MALLOC_CAP_SPIRAM ,
  idfxx::memory::capabilities::internal = MALLOC_CAP_INTERNAL ,
  idfxx::memory::capabilities::default_heap = MALLOC_CAP_DEFAULT ,
  idfxx::memory::capabilities::iram = MALLOC_CAP_IRAM_8BIT ,
  idfxx::memory::capabilities::retention = MALLOC_CAP_RETENTION ,
  idfxx::memory::capabilities::rtc = MALLOC_CAP_RTCRAM ,
  idfxx::memory::capabilities::dma_desc_ahb = MALLOC_CAP_DMA_DESC_AHB ,
  idfxx::memory::capabilities::dma_desc_axi = MALLOC_CAP_DMA_DESC_AXI ,
  idfxx::memory::capabilities::cache_aligned = MALLOC_CAP_CACHE_ALIGNED ,
  idfxx::memory::capabilities::dram = internal | access_8bit
}
 Memory capability flags for heap allocations. More...
 

Functions

size_t idfxx::memory::total_size (flags< capabilities > c) noexcept
 Returns the total size of heap regions matching the given capabilities.
 
size_t idfxx::memory::free_size (flags< capabilities > c) noexcept
 Returns the current free size of heap regions matching the given capabilities.
 
size_t idfxx::memory::largest_free_block (flags< capabilities > c) noexcept
 Returns the largest free block in heap regions matching the given capabilities.
 
size_t idfxx::memory::minimum_free_size (flags< capabilities > c) noexcept
 Returns the minimum free size since boot for heap regions matching the given capabilities.
 
info idfxx::memory::get_info (flags< capabilities > c) noexcept
 Returns detailed heap statistics for regions matching the given capabilities.
 
template<typename F >
void idfxx::memory::walk (flags< capabilities > 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< capabilities > 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< capabilities > 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.
 
voididfxx::malloc (size_t size, flags< memory::capabilities > c) noexcept
 Allocates memory from heap regions matching the given capabilities.
 
voididfxx::calloc (size_t n, size_t size, flags< memory::capabilities > c) noexcept
 Allocates zero-initialized memory from heap regions matching the given capabilities.
 
voididfxx::realloc (void *ptr, size_t size, flags< memory::capabilities > 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.
 
voididfxx::aligned_alloc (size_t alignment, size_t size, flags< memory::capabilities > c) noexcept
 Allocates aligned memory from heap regions matching the given capabilities.
 
voididfxx::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.
 
template<typename T , typename U , flags< memory::capabilities > Caps, size_t Alignment>
constexpr bool idfxx::operator== (const allocator< T, Caps, Alignment > &, const allocator< U, Caps, Alignment > &) noexcept
 Equality comparison for allocator.
 

Detailed Description

IDFXX memory utilities.

Definition in file memory.hpp.