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 261 of file allocator.h.

261 {
262 // Check if allocation is too large for this slab
263 if (n > BLOCKS_PER_SLAB) {
264 return nullptr;
265 }
266
267 // Use bitset's find_run to find n contiguous free blocks (false = free)
268 fl::i32 start = slab->allocated_blocks.find_run(false, static_cast<fl::u32>(n));
269 if (start >= 0) {
270 // Mark blocks as allocated
271 for (fl::size i = 0; i < n; ++i) {
272 slab->allocated_blocks.set(static_cast<fl::u32>(start + i), true);
273 }
274 slab->allocated_count += n;
276
277 // Return pointer to the first block
278 return slab->memory + static_cast<fl::size>(start) * BLOCK_SIZE;
279 }
280
281 return nullptr;
282 }
static constexpr fl::size BLOCK_SIZE
Definition allocator.h:187
static constexpr fl::size BLOCKS_PER_SLAB
Definition allocator.h:188
fl::size total_allocated_
Definition allocator.h:207

References fl::SlabAllocator< T, SLAB_SIZE >::Slab::allocated_blocks, fl::SlabAllocator< T, SLAB_SIZE >::Slab::allocated_count, BLOCK_SIZE, BLOCKS_PER_SLAB, fl::SlabAllocator< T, SLAB_SIZE >::Slab::memory, and total_allocated_.

Referenced by allocateFromSlab().

+ Here is the caller graph for this function: