Deluge Firmware 1.3.0
Build date: 2025.06.05
Loading...
Searching...
No Matches
external_allocator.h
1#pragma once
2#include "memory/general_memory_allocator.h"
3#include "util/exceptions.h"
4#include <cstddef>
5extern "C" {
6void abort(void); // this is defined in reset_handler.S
7}
8namespace deluge::memory {
9
17template <typename T>
18class external_allocator {
19public:
20 using value_type = T;
21
22 constexpr external_allocator() noexcept = default;
23
24 template <typename U>
25 constexpr external_allocator(const external_allocator<U>&) noexcept {};
26
27 [[nodiscard]] T* allocate(std::size_t n) noexcept(false) {
28 if (n == 0) {
29 return nullptr;
30 }
31 void* addr = GeneralMemoryAllocator::get().allocExternal(n * sizeof(T));
32 if (addr == nullptr) [[unlikely]] {
33 throw deluge::exception::BAD_ALLOC;
34 }
35 return static_cast<T*>(addr);
36 }
37
38 void deallocate(T* p, std::size_t n) { GeneralMemoryAllocator::get().deallocExternal(p); }
39
40 template <typename U>
41 bool operator==(const deluge::memory::external_allocator<U>& o) {
42 return true;
43 }
44
45 template <typename U>
46 bool operator!=(const deluge::memory::external_allocator<U>& o) {
47 return false;
48 }
49};
50} // namespace deluge::memory
A simple GMA wrapper that conforms to the C++ Allocator trait spec (see: https://en....
Definition external_allocator.h:18