FastLED 3.10.6
Loading...
Searching...
No Matches

◆ allocate()

template<typename T, fl::size SLAB_SIZE = FASTLED_DEFAULT_SLAB_SIZE>
T * fl::SlabAllocator< T, SLAB_SIZE >::allocate ( fl::size n = 1)
inline

Definition at line 625 of file allocator.h.

625 {
626 if (n == 0) {
627 return nullptr;
628 }
629
630 // Thread safety (FastLED#3588): slab-backed containers
631 // (fl::map/set via allocator_slab) share a static per-type
632 // SlabAllocator across FreeRTOS tasks — e.g. the esp_http_server
633 // task building Response headers while the main loop mutates its
634 // own maps. Unsynchronized free-list/bitset updates corrupted
635 // the slab and crashed classic ESP32 under WiFi traffic.
637
638 // Try to allocate from slab first
639 void* ptr = allocateFromSlab(n);
640 if (ptr) {
641 fl::memset(ptr, 0, sizeof(T) * n);
642 return static_cast<T*>(ptr);
643 }
644
645 // Fall back to regular malloc for large allocations
646 ptr = Malloc(sizeof(T) * n);
647 if (ptr) {
648 fl::memset(ptr, 0, sizeof(T) * n);
649 }
650 return static_cast<T*>(ptr);
651 }
void * allocateFromSlab(fl::size n=1) FL_NO_EXCEPT
Definition allocator.h:517
fl::detail::slab_mutex mMutex
Definition allocator.h:487
void * memset(void *s, int c, size_t n) FL_NO_EXCEPT
void * Malloc(fl::size size)

References allocateFromSlab(), fl::FL_NO_EXCEPT, fl::Malloc(), fl::memset(), and mMutex.

+ Here is the call graph for this function: