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

907 {
908 if (n == 0) {
909 return nullptr;
910 }
911
912 // For large allocations (n > 1), use base allocator directly
913 if (n > 1) {
914 T* ptr = mBaseAllocator.allocate(n);
915 if (ptr) {
917 }
918 return ptr;
919 }
920
921 // For single allocations, first try inlined memory
922 // Find first free inlined slot
923 fl::i32 free_slot = mFreeBits.find_first(false);
924 if (free_slot >= 0 && static_cast<fl::size>(free_slot) < N) {
925 // Mark the inlined slot as used
926 mFreeBits.set(static_cast<fl::u32>(free_slot), true);
927
928 // Update inlined usage tracking
929 if (static_cast<fl::size>(free_slot) + 1 > mInlinedUsed) {
930 mInlinedUsed = static_cast<fl::size>(free_slot) + 1;
931 }
933 return &get_inlined_ptr()[static_cast<fl::size>(free_slot)];
934 }
935
936 // No inlined slots available, use heap allocation
937 T* ptr = mBaseAllocator.allocate(1);
938 if (ptr) {
940 }
941 return ptr;
942 }
BaseAllocator mBaseAllocator
Definition allocator.h:832
fl::size mActiveAllocations
Definition allocator.h:835
T * get_inlined_ptr() FL_NO_EXCEPT
Definition allocator.h:1015
fl::bitset_fixed< N > mFreeBits
Definition allocator.h:834