FastLED 3.9.15
Loading...
Searching...
No Matches

◆ findContiguousBlocks()

template<typename T, fl::size SLAB_SIZE = FASTLED_DEFAULT_SLAB_SIZE>
void * fl::SlabAllocator< T, SLAB_SIZE >::findContiguousBlocks ( Slab * slab,
fl::size n )
inlineprivate

Definition at line 536 of file allocator.h.

536 {
537 // Check if allocation is too large for this slab
538 if (n > BLOCKS_PER_SLAB) {
539 return nullptr;
540 }
541
542 // Use bitset's find_run to find n contiguous free blocks (false = free)
543 fl::i32 start = slab->allocated_blocks.find_run(false, static_cast<fl::u32>(n));
544 if (start >= 0) {
545 // Mark blocks as allocated
546 for (fl::size i = 0; i < n; ++i) {
547 slab->allocated_blocks.set(static_cast<fl::u32>(start + i), true);
548 }
549 slab->allocated_count += n;
551
552 // Return pointer to the first block
553 return slab->memory + static_cast<fl::size>(start) * SLAB_BLOCK_SIZE;
554 }
555
556 return nullptr;
557 }
static constexpr fl::size BLOCKS_PER_SLAB
Definition allocator.h:465
static constexpr fl::size SLAB_BLOCK_SIZE
Definition allocator.h:464
fl::size mTotalAllocated
Definition allocator.h:484

References BLOCKS_PER_SLAB, FL_NOEXCEPT, mTotalAllocated, and SLAB_BLOCK_SIZE.

Referenced by allocateFromSlab().

+ Here is the caller graph for this function: