MCPcopy Create free account
hub / github.com/FastLED/FastLED / allocator_inlined

Class allocator_inlined

src/fl/stl/allocator.h:805–1040  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

803// Falls back to the base allocator for additional elements
804template <typename T, fl::size N, typename BaseAllocator = fl::allocator<T>>
805class allocator_inlined {
806private:
807
808 // Inlined storage block
809 struct InlinedStorage {
810 FL_ALIGN_AS(T) u8 data[N * sizeof(T)];
811
812 InlinedStorage() FL_NOEXCEPT {
813 fl::memset(data, 0, sizeof(data));
814 }
815 };
816
817 InlinedStorage mInlinedStorage;
818 BaseAllocator mBaseAllocator;
819 fl::size mInlinedUsed = 0;
820 fl::bitset_fixed<N> mFreeBits; // Track free slots for inlined memory only
821 fl::size mActiveAllocations = 0; // Track current active allocations
822
823public:
824 // Type definitions required by STL
825 using value_type = T;
826 using pointer = T*;
827 using const_pointer = const T*;
828 using reference = T&;
829 using const_reference = const T&;
830 using size_type = fl::size;
831 using difference_type = fl::ptrdiff_t;
832
833 // Rebind allocator to type U
834 template <typename U>
835 struct rebind {
836 using other = allocator_inlined<U, N, typename BaseAllocator::template rebind<U>::other>;
837 };
838
839 // Default constructor
840 allocator_inlined() FL_NOEXCEPT = default;
841
842 // Copy constructor
843 allocator_inlined(const allocator_inlined& other) FL_NOEXCEPT {
844 // Copy inlined data
845 mInlinedUsed = other.mInlinedUsed;
846 for (fl::size i = 0; i < mInlinedUsed; ++i) {
847 new (&get_inlined_ptr()[i]) T(other.get_inlined_ptr()[i]);
848 }
849
850 // Copy free bits
851 mFreeBits = other.mFreeBits;
852
853 // Note: Heap allocations are not copied, only inlined data
854
855 // Copy active allocations count
856 mActiveAllocations = other.mActiveAllocations;
857 }
858
859 // Copy assignment
860 allocator_inlined& operator=(const allocator_inlined& other) FL_NOEXCEPT {
861 if (this != &other) {
862 clear();

Callers

nothing calls this directly

Calls 4

get_inlined_ptrMethod · 0.80
clearFunction · 0.70
cleanupMethod · 0.65
resetMethod · 0.45

Tested by

no test coverage detected