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

236 {
237 // Try to find n contiguous free blocks in existing slabs
238 for (Slab* slab = slabs_; slab; slab = slab->next) {
239 void* ptr = findContiguousBlocks(slab, n);
240 if (ptr) {
241 return ptr;
242 }
243 }
244
245 // No contiguous blocks found, create new slab if n fits
246 if (n <= BLOCKS_PER_SLAB) {
247 if (!createSlab()) {
248 return nullptr; // Out of memory
249 }
250
251 // Try again with the new slab
253 }
254
255 // Request too large for slab, fall back to malloc
256 return nullptr;
257 }
static constexpr fl::size BLOCKS_PER_SLAB
Definition allocator.h:188
void * findContiguousBlocks(Slab *slab, fl::size n)
Definition allocator.h:261
Slab * createSlab()
Definition allocator.h:210

References BLOCKS_PER_SLAB, createSlab(), findContiguousBlocks(), and slabs_.

Referenced by allocate().

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