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

893 {
894 if (n == 0) {
895 return nullptr;
896 }
897
898 // For large allocations (n > 1), use base allocator directly
899 if (n > 1) {
900 T* ptr = mBaseAllocator.allocate(n);
901 if (ptr) {
903 }
904 return ptr;
905 }
906
907 // For single allocations, first try inlined memory
908 // Find first free inlined slot
909 fl::i32 free_slot = mFreeBits.find_first(false);
910 if (free_slot >= 0 && static_cast<fl::size>(free_slot) < N) {
911 // Mark the inlined slot as used
912 mFreeBits.set(static_cast<fl::u32>(free_slot), true);
913
914 // Update inlined usage tracking
915 if (static_cast<fl::size>(free_slot) + 1 > mInlinedUsed) {
916 mInlinedUsed = static_cast<fl::size>(free_slot) + 1;
917 }
919 return &get_inlined_ptr()[static_cast<fl::size>(free_slot)];
920 }
921
922 // No inlined slots available, use heap allocation
923 T* ptr = mBaseAllocator.allocate(1);
924 if (ptr) {
926 }
927 return ptr;
928 }
BaseAllocator mBaseAllocator
Definition allocator.h:818
fl::size mActiveAllocations
Definition allocator.h:821
T * get_inlined_ptr() FL_NOEXCEPT
Definition allocator.h:1001
fl::bitset_fixed< N > mFreeBits
Definition allocator.h:820