9#include "esp_heap_caps.h"
10#include "esp_system.h"
20 void *out = heap_caps_malloc(size, MALLOC_CAP_SPIRAM);
23 out = heap_caps_malloc(size, MALLOC_CAP_DEFAULT);
36#if defined(FASTLED_TESTING)
38MallocFreeHook* gMallocFreeHook =
nullptr;
40int& tls_reintrancy_count() {
46 int& reintrancy_count;
47 MemoryGuard(): reintrancy_count(tls_reintrancy_count()) {
53 bool enabled()
const {
54 return reintrancy_count <= 1;
62#if defined(FASTLED_TESTING)
63void SetMallocFreeHook(MallocFreeHook* hook) {
64 gMallocFreeHook = hook;
67void ClearMallocFreeHook() {
68 gMallocFreeHook =
nullptr;
79 void *ptr = Alloc(size);
84#if defined(FASTLED_TESTING)
85 if (gMallocFreeHook && ptr) {
86 MemoryGuard allows_hook;
87 if (allows_hook.enabled()) {
88 gMallocFreeHook->onMalloc(ptr, size);
97#if defined(FASTLED_TESTING)
98 if (gMallocFreeHook && ptr) {
100 MemoryGuard allows_hook;
101 if (allows_hook.enabled()) {
102 gMallocFreeHook->onFree(ptr);
111 void* ptr = Alloc(size);
113#if defined(FASTLED_TESTING)
114 if (gMallocFreeHook && ptr) {
115 MemoryGuard allows_hook;
116 if (allows_hook.enabled()) {
117 gMallocFreeHook->onMalloc(ptr, size);
126#if defined(FASTLED_TESTING)
127 if (gMallocFreeHook && ptr) {
128 MemoryGuard allows_hook;
129 if (allows_hook.enabled()) {
130 gMallocFreeHook->onFree(ptr);
Implements the FastLED namespace macros.
void DefaultFree(void *ptr)
void * DefaultAlloc(fl::size size)
ThreadLocalFake< T > ThreadLocal
void SetPSRamAllocator(void *(*alloc)(fl::size), void(*free)(void *))
void PSRamDeallocate(void *ptr)
void * Malloc(fl::size size)
void * PSRamAllocate(fl::size size, bool zero)