FastLED 3.10.6
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 491 of file allocator.h.

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