FastLED 3.9.15
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 513 of file allocator.h.

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

References BLOCKS_PER_SLAB, createSlab(), findContiguousBlocks(), FL_NOEXCEPT, and mSlabs.

Referenced by allocate().

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