HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
locked_memory_allocator.hpp
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include <type_traits>
8#include <cstddef>
9
10namespace tt {
11
12[[nodiscard]] std::byte *locked_memory_allocator_allocate(size_t n) noexcept;
13
14void locked_memory_allocator_deallocate(std::byte *p, size_t n) noexcept;
15
16template<typename T>
18public:
19 using value_type = T;
20 using size_type = size_t;
21 using difference_type = ptrdiff_t;
22
23 template<typename U>
24 struct rebind {
26 };
27
28 constexpr locked_memory_allocator() noexcept {};
29
30 constexpr locked_memory_allocator(locked_memory_allocator const &other) noexcept {}
31
32 template<typename U>
33 constexpr locked_memory_allocator(locked_memory_allocator<U> const &other) noexcept {}
34
35 [[nodiscard]] value_type *allocate(size_type n) const noexcept
36 {
37 auto *p = locked_memory_allocator_allocate(n * sizeof(value_type));
38 return reinterpret_cast<value_type *>(p);
39 }
40
41 void deallocate(value_type *p, size_type n) const noexcept
42 {
43 locked_memory_allocator_deallocate(reinterpret_cast<std::byte *>(p), n * sizeof(value_type));
44 }
45};
46
47}
Definition locked_memory_allocator.hpp:17
Definition locked_memory_allocator.hpp:24