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

◆ createSlab()

template<typename T, fl::size SLAB_SIZE = FASTLED_DEFAULT_SLAB_SIZE>
Slab * fl::SlabAllocator< T, SLAB_SIZE >::createSlab ( )
inlineprivate

Definition at line 487 of file allocator.h.

487 {
488 Slab* slab = static_cast<Slab*>(Malloc(sizeof(Slab)));
489 if (!slab) {
490 return nullptr;
491 }
492
493 // Use placement new to properly initialize the Slab
494 new(slab) Slab();
495
496 slab->memory = static_cast<u8*>(Malloc(SLAB_MEMORY_SIZE));
497 if (!slab->memory) {
498 slab->~Slab();
499 Free(slab);
500 return nullptr;
501 }
502
503 // Initialize all blocks in the slab as free
504 slab->allocated_blocks.reset(); // All blocks start as free
505
506 // Add slab to the slab list
507 slab->next = mSlabs;
508 mSlabs = slab;
509
510 return slab;
511 }
static constexpr fl::size SLAB_MEMORY_SIZE
Definition allocator.h:466
void Free(void *ptr)
void * Malloc(fl::size size)

References fl::SlabAllocator< T, SLAB_SIZE >::Slab::~Slab(), fl::SlabAllocator< T, SLAB_SIZE >::Slab::allocated_blocks, FL_NOEXCEPT, fl::Free(), fl::Malloc(), fl::SlabAllocator< T, SLAB_SIZE >::Slab::memory, mSlabs, fl::SlabAllocator< T, SLAB_SIZE >::Slab::next, and SLAB_MEMORY_SIZE.

Referenced by allocateFromSlab().

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