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 hi::inline v1 {
11
12[[nodiscard]] std::byte *locked_memory_allocator_allocate(std::size_t n) noexcept;
13
14void locked_memory_allocator_deallocate(std::byte *p, std::size_t n) noexcept;
15
16template<typename T>
18public:
19 using value_type = T;
20 using size_type = std::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 }
36
37 [[nodiscard]] value_type *allocate(size_type n) const noexcept
38 {
39 auto *p = locked_memory_allocator_allocate(n * sizeof(value_type));
40 return reinterpret_cast<value_type *>(p);
41 }
42
43 void deallocate(value_type *p, size_type n) const noexcept
44 {
45 locked_memory_allocator_deallocate(reinterpret_cast<std::byte *>(p), n * sizeof(value_type));
46 }
47};
48
49} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:15
Definition locked_memory_allocator.hpp:17
Definition locked_memory_allocator.hpp:24