9#include <esp_heap_caps.h>
56 if (n==0)
return nullptr;
60 assert(n <= std::numeric_limits<size_type>::max() /
sizeof(T));
64 heap_caps_malloc(n *
sizeof(T), MALLOC_CAP_SPIRAM));
66 p =
static_cast<pointer>(malloc(n *
sizeof(T)));
71 if (!p)
throw std::bad_alloc();
83 if (p) heap_caps_free(p);
101 template <
typename U>
Custom allocator that uses ESP32's PSRAM for memory allocation.
Definition: Allocator.h:24
std::size_t size_type
Definition: Allocator.h:31
bool operator!=(const AllocatorPSRAM< U > &) const noexcept
Definition: Allocator.h:102
const T & const_reference
Definition: Allocator.h:30
std::true_type is_always_equal
Definition: Allocator.h:33
const T * const_pointer
Definition: Allocator.h:28
T value_type
Definition: Allocator.h:26
pointer allocate(size_type n)
Allocate memory from PSRAM.
Definition: Allocator.h:55
void deallocate(pointer p, size_type) noexcept
Deallocate memory.
Definition: Allocator.h:81
AllocatorPSRAM(const AllocatorPSRAM< U > &) noexcept
Copy constructor from another allocator type.
Definition: Allocator.h:47
std::true_type propagate_on_container_move_assignment
Definition: Allocator.h:34
AllocatorPSRAM() noexcept
Default constructor.
Definition: Allocator.h:39
T * pointer
Definition: Allocator.h:27
bool operator==(const AllocatorPSRAM< U > &) const noexcept
Definition: Allocator.h:100
std::ptrdiff_t difference_type
Definition: Allocator.h:32
T & reference
Definition: Allocator.h:29
Definition: Allocator.h:13
std::basic_string< char, std::char_traits< char >, AllocatorPSRAM< char > > stringPSRAM
Definition: Allocator.h:106
Rebind allocator to another type.
Definition: Allocator.h:94