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

210 {
211 Slab* slab = static_cast<Slab*>(malloc(sizeof(Slab)));
212 if (!slab) {
213 return nullptr;
214 }
215
216 // Use placement new to properly initialize the Slab
217 new(slab) Slab();
218
219 slab->memory = static_cast<u8*>(malloc(SLAB_MEMORY_SIZE));
220 if (!slab->memory) {
221 slab->~Slab();
222 free(slab);
223 return nullptr;
224 }
225
226 // Initialize all blocks in the slab as free
227 slab->allocated_blocks.reset(); // All blocks start as free
228
229 // Add slab to the slab list
230 slab->next = slabs_;
231 slabs_ = slab;
232
233 return slab;
234 }
static constexpr fl::size SLAB_MEMORY_SIZE
Definition allocator.h:189

References fl::SlabAllocator< T, SLAB_SIZE >::Slab::~Slab(), fl::SlabAllocator< T, SLAB_SIZE >::Slab::allocated_blocks, fl::SlabAllocator< T, SLAB_SIZE >::Slab::memory, fl::SlabAllocator< T, SLAB_SIZE >::Slab::next, SLAB_MEMORY_SIZE, and slabs_.

Referenced by allocateFromSlab().

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