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

◆ allocateFromSlab()

template<typename T, fl::size SLAB_SIZE = FASTLED_DEFAULT_SLAB_SIZE>
void * fl::SlabAllocator< T, SLAB_SIZE >::allocateFromSlab ( fl::size n = 1)
inlineprivate

Definition at line 517 of file allocator.h.

517 {
518 // Try to find n contiguous free blocks in existing slabs
519 for (Slab* slab = mSlabs; slab; slab = slab->next) {
520 void* ptr = findContiguousBlocks(slab, n);
521 if (ptr) {
522 return ptr;
523 }
524 }
525
526 // No contiguous blocks found, create new slab if n fits
527 if (n <= BLOCKS_PER_SLAB) {
528 if (!createSlab()) {
529 return nullptr; // Out of memory
530 }
531
532 // Try again with the new slab
534 }
535
536 // Request too large for slab, fall back to malloc
537 return nullptr;
538 }
Slab * createSlab() FL_NO_EXCEPT
Definition allocator.h:491
static constexpr fl::size BLOCKS_PER_SLAB
Definition allocator.h:466
void * findContiguousBlocks(Slab *slab, fl::size n) FL_NO_EXCEPT
Definition allocator.h:540

References BLOCKS_PER_SLAB, createSlab(), findContiguousBlocks(), fl::FL_NO_EXCEPT, and mSlabs.

Referenced by allocate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: