152#define FL_USE_PSRAM_ALLOCATOR(TYPE) \
153template <> \
154class allocator<TYPE> { \
155 public: \
156 using value_type = TYPE; \
157 using pointer = TYPE*; \
158 using const_pointer = const TYPE*; \
159 using reference = TYPE&; \
160 using const_reference = const TYPE&; \
161 using size_type = size_t; \
162 using difference_type = ptrdiff_t; \
163 \
164 template <typename U> \
165 struct rebind { \
166 using other = allocator<U>; \
167 }; \
168 \
169 allocator() noexcept {} \
170 \
171 template <typename U> \
172 allocator(const allocator<U>&) noexcept {} \
173 \
174 ~allocator() noexcept {} \
175 \
176 TYPE *allocate(size_t n) { \
177 return reinterpret_cast<TYPE *>(PSRamAllocate(sizeof(TYPE) * n, true)); \
178 } \
179 void deallocate(TYPE *p, size_t n) { \
180 if (p == nullptr) { \
181 return; \
182 } \
183 PSRamDeallocate(p); \
184 } \
185 \
186 template <typename U, typename... Args> \
187 void construct(U* p, Args&&... args) { \
188 new(static_cast<void*>(p)) U(fl::forward<Args>(args)...); \
189 } \
190 \
191 template <typename U> \
192 void destroy(U* p) { \
193 p->~U(); \
194 } \
195};