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

◆ allocate()

template<typename T, fl::size N, typename BaseAllocator = fl::allocator<T>>
T * fl::allocator_inlined< T, N, BaseAllocator >::allocate ( fl::size n)
inline

Definition at line 609 of file allocator.h.

609 {
610 if (n == 0) {
611 return nullptr;
612 }
613
614 // For large allocations (n > 1), use base allocator directly
615 if (n > 1) {
616 T* ptr = m_base_allocator.allocate(n);
617 if (ptr) {
619 }
620 return ptr;
621 }
622
623 // For single allocations, first try inlined memory
624 // Find first free inlined slot
625 fl::i32 free_slot = m_free_bits.find_first(false);
626 if (free_slot >= 0 && static_cast<fl::size>(free_slot) < N) {
627 // Mark the inlined slot as used
628 m_free_bits.set(static_cast<fl::u32>(free_slot), true);
629
630 // Update inlined usage tracking
631 if (static_cast<fl::size>(free_slot) + 1 > m_inlined_used) {
632 m_inlined_used = static_cast<fl::size>(free_slot) + 1;
633 }
635 return &get_inlined_ptr()[static_cast<fl::size>(free_slot)];
636 }
637
638 // No inlined slots available, use heap allocation
639 T* ptr = m_base_allocator.allocate(1);
640 if (ptr) {
642 }
643 return ptr;
644 }
BaseAllocator m_base_allocator
Definition allocator.h:534
fl::bitset_fixed< N > m_free_bits
Definition allocator.h:536
fl::size m_active_allocations
Definition allocator.h:537