1#include "platforms/is_platform.h"
12#include "esp_heap_caps.h"
13#include "esp_system.h"
15#include "platforms/esp/esp_version.h"
30template <
typename Allocator>
33template <
typename Allocator>
41#ifdef FL_VECTOR_PSRAM_ALWAYS_SRAM
43 void *out = heap_caps_malloc(size, MALLOC_CAP_DEFAULT);
45 void *out = heap_caps_malloc(size, MALLOC_CAP_SPIRAM);
48 out = heap_caps_malloc(size, MALLOC_CAP_DEFAULT);
62#if defined(FASTLED_TESTING)
71struct MallocFreeHookState {
72 MallocFreeHook* hook =
nullptr;
83 int& reintrancy_count;
84 MemoryGuard()
FL_NO_EXCEPT : reintrancy_count(tls_reintrancy_count()) {
91 return reintrancy_count <= 1;
102 (void)tls_reintrancy_count();
105FL_INIT(allocator_init_wrapper, init_tls_reentrancy)
111#if defined(FASTLED_TESTING)
112void SetMallocFreeHook(MallocFreeHook* hook)
FL_NO_EXCEPT {
116 (void)tls_reintrancy_count();
118 malloc_free_hook() = hook;
122 malloc_free_hook() =
nullptr;
133 void *ptr = Alloc(size);
138#if defined(FASTLED_TESTING)
139 if (malloc_free_hook() && ptr) {
140 MemoryGuard allows_hook;
141 if (allows_hook.enabled()) {
142 malloc_free_hook()->onMalloc(ptr, size);
151#if defined(FASTLED_TESTING)
152 if (malloc_free_hook() && ptr) {
154 MemoryGuard allows_hook;
155 if (allows_hook.enabled()) {
156 malloc_free_hook()->onFree(ptr);
165 void* ptr = Alloc(size);
167#if defined(FASTLED_TESTING)
168 if (malloc_free_hook() && ptr) {
169 MemoryGuard allows_hook;
170 if (allows_hook.enabled()) {
171 malloc_free_hook()->onMalloc(ptr, size);
180#if defined(FASTLED_TESTING)
181 if (malloc_free_hook() && ptr) {
182 MemoryGuard allows_hook;
183 if (allows_hook.enabled()) {
184 malloc_free_hook()->onFree(ptr);
196void* InternalAlloc(fl::size size) {
199 void* ptr = heap_caps_malloc(size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
206void* InternalRealloc(
void* ptr, fl::size size) {
208 void* new_ptr = heap_caps_realloc(ptr, size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
218void InternalFree(
void* ptr) {
222void* DMAAlloc(fl::size size) {
232 fl::size aligned_size = ((size + 63) / 64) * 64;
234#if ESP_IDF_VERSION_4_OR_HIGHER
236 void* ptr = heap_caps_aligned_alloc(64, aligned_size, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
239 void* ptr = heap_caps_malloc(aligned_size, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
247void DMAFree(
void* ptr) {
265 static constexpr int MAX = 64;
275 auto& s = slab_registry_state();
276 for (
int i = 0; i < s.count; i++) {
277 if (s.entries[i].block_size == block_size &&
278 s.entries[i].slab_size == slab_size) {
279 return s.entries[i].allocator;
286 auto& s = slab_registry_state();
288 for (
int i = 0; i < s.count; i++) {
289 if (s.entries[i].block_size == block_size &&
290 s.entries[i].slab_size == slab_size) {
296 if (s.count < SlabRegistryState::MAX) {
297 s.entries[s.count++] = {block_size, slab_size,
allocator};
static T & instance() FL_NO_EXCEPT
static T & instance() FL_NO_EXCEPT
void * DefaultAlloc(fl::size size) FL_NO_EXCEPT
void DefaultFree(void *ptr) FL_NO_EXCEPT
SlabRegistryState & slab_registry_state() FL_NO_EXCEPT
void * slab_allocator_registry_get(fl::size block_size, fl::size slab_size) FL_NO_EXCEPT
void slab_allocator_registry_set(fl::size block_size, fl::size slab_size, void *allocator) FL_NO_EXCEPT
Compile-time linker keep-alive hook for a single fl::Bus.
u8 u8 fract8 blur_amount FL_NO_EXCEPT
FASTLED_FORCE_INLINE void free(void *ptr) FL_NO_EXCEPT
void SetPSRamAllocator(void *(*alloc)(fl::size), void(*free)(void *)) FL_NO_EXCEPT
void Free(void *ptr) FL_NO_EXCEPT
FASTLED_FORCE_INLINE void * malloc(size_t size) FL_NO_EXCEPT
FASTLED_FORCE_INLINE void * memset(void *s, int c, size_t n) FL_NO_EXCEPT
void * PSRamAllocate(fl::size size, bool zero) FL_NO_EXCEPT
void * Malloc(fl::size size) FL_NO_EXCEPT
void PSRamDeallocate(void *ptr) FL_NO_EXCEPT
Base definition for an LED controller.
static constexpr bool has_allocate_at_least_v
static constexpr bool has_reallocate_v
SlabRegistryEntry entries[MAX]