HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
locked_memory_allocator_intf.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 "../macros.hpp"
8#include <type_traits>
9#include <cstddef>
10
11hi_export_module(hikogui.memory.locked_memory_allocator : intf);
12
13hi_export namespace hi::inline v1 {
14
15[[nodiscard]] std::byte *locked_memory_allocator_allocate(std::size_t n) noexcept;
16
17void locked_memory_allocator_deallocate(std::byte *p, std::size_t n) noexcept;
18
19template<typename T>
21public:
22 using value_type = T;
23 using size_type = std::size_t;
24 using difference_type = ptrdiff_t;
25
26 template<typename U>
27 struct rebind {
29 };
30
31 constexpr locked_memory_allocator() noexcept {};
32
33 constexpr locked_memory_allocator(locked_memory_allocator const &other) noexcept {}
34
35 template<typename U>
36 constexpr locked_memory_allocator(locked_memory_allocator<U> const &other) noexcept
37 {
38 }
39
40 [[nodiscard]] value_type *allocate(size_type n) const noexcept
41 {
42 auto *p = locked_memory_allocator_allocate(n * sizeof(value_type));
43 return reinterpret_cast<value_type *>(p);
44 }
45
46 void deallocate(value_type *p, size_type n) const noexcept
47 {
48 locked_memory_allocator_deallocate(reinterpret_cast<std::byte *>(p), n * sizeof(value_type));
49 }
50};
51
52} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition locked_memory_allocator_intf.hpp:20
Definition locked_memory_allocator_intf.hpp:27