| 803 | // Falls back to the base allocator for additional elements |
| 804 | template <typename T, fl::size N, typename BaseAllocator = fl::allocator<T>> |
| 805 | class allocator_inlined { |
| 806 | private: |
| 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 | |
| 823 | public: |
| 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(); |
nothing calls this directly
no test coverage detected