23#include <esp_heap_caps.h>
24#include <esp_system.h>
43 internal = MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT,
44 spiram = MALLOC_CAP_SPIRAM,
85 void* p = heap_caps_malloc(n *
sizeof(T), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
87#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
88 throw std::bad_alloc();
90 esp_system_abort(
"dram_allocator: allocation failed");
93 return static_cast<T*
>(p);
101 void deallocate(T* p,
size_t)
noexcept { heap_caps_free(p); }
111template<
typename T,
typename U>
123template<
typename T,
typename U>
168 void* p = heap_caps_malloc(n *
sizeof(T), MALLOC_CAP_SPIRAM);
170#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
171 throw std::bad_alloc();
173 esp_system_abort(
"spiram_allocator: allocation failed");
176 return static_cast<T*
>(p);
184 void deallocate(T* p,
size_t)
noexcept { heap_caps_free(p); }
194template<
typename T,
typename U>
206template<
typename T,
typename U>
248 void* p = heap_caps_malloc(n *
sizeof(T), MALLOC_CAP_DMA);
250#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
251 throw std::bad_alloc();
253 esp_system_abort(
"dma_allocator: allocation failed");
256 return static_cast<T*
>(p);
264 void deallocate(T* p,
size_t)
noexcept { heap_caps_free(p); }
274template<
typename T,
typename U>
286template<
typename T,
typename U>
bool operator!=(const dram_allocator< T > &, const dram_allocator< U > &)
Inequality comparison for dram_allocator.
bool operator==(const dram_allocator< T > &, const dram_allocator< U > &)
Equality comparison for dram_allocator.
memory_type
Memory region type for heap allocations.
@ internal
Internal DRAM (default)
STL-compatible allocator for DMA-capable memory.
dma_allocator()=default
Default constructor.
constexpr dma_allocator(const dma_allocator< U > &) noexcept
Rebinding copy constructor.
T * allocate(size_t n)
Allocates DMA-capable 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.
STL-compatible allocator for internal DRAM.
constexpr dram_allocator(const dram_allocator< U > &) noexcept
Rebinding copy constructor.
T * allocate(size_t n)
Allocates memory for n objects of type T from internal DRAM.
dram_allocator()=default
Default constructor.
void deallocate(T *p, size_t) noexcept
Deallocates memory previously allocated by this allocator.
T value_type
The type of object to allocate.
STL-compatible allocator for external PSRAM (SPI RAM).
T value_type
The type of object to allocate.
void deallocate(T *p, size_t) noexcept
Deallocates memory previously allocated by this allocator.
spiram_allocator()=default
Default constructor.
constexpr spiram_allocator(const spiram_allocator< U > &) noexcept
Rebinding copy constructor.
T * allocate(size_t n)
Allocates memory for n objects of type T from external PSRAM.