Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
sdram_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
18template <typename T>
19class sdram_allocator {
20public:
21 using value_type = T;
22
23 constexpr sdram_allocator() noexcept = default;
24
25 template <typename U>
26 constexpr sdram_allocator(const sdram_allocator<U>&) noexcept {};
27
28 [[nodiscard]] T* allocate(std::size_t n) noexcept(false) {
29 if (n == 0) {
30 return nullptr;
31 }
32 void* addr = GeneralMemoryAllocator::get().allocLowSpeed(n * sizeof(T));
33 if (addr == nullptr) [[unlikely]] {
34 throw deluge::exception::BAD_ALLOC;
35 }
36 return static_cast<T*>(addr);
37 }
38
39 void deallocate(T* p, std::size_t n) { GeneralMemoryAllocator::get().dealloc(p); }
40
41 template <typename U>
42 bool operator==(const sdram_allocator<U>& o) {
43 return true;
44 }
45
46 template <typename U>
47 bool operator!=(const sdram_allocator<U>& o) {
48 return false;
49 }
50};
51} // namespace deluge::memory