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