libcaramel
memory_resource.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <libcaramel/util/types.hpp>
12 
13 #include <gsl/pointers>
14 
15 #include <cstddef>
16 
17 namespace caramel
18 {
23  {
24  public:
25  using pointer = void*;
26  using const_pointer = const void*;
27 
28  public:
29  memory_resource() noexcept = default;
30  memory_resource(const memory_resource&) noexcept = default;
31  memory_resource(memory_resource&&) noexcept = default;
32  virtual ~memory_resource() noexcept = default;
33 
34  auto operator=(const memory_resource&) noexcept -> memory_resource& = default;
35  auto operator=(memory_resource&&) noexcept -> memory_resource& = default;
36 
46  auto operator==(const memory_resource& rhs) const -> bool;
47 
59  virtual auto allocate(count_t bytes, align_t alignment) noexcept -> pointer = 0;
70  virtual void deallocate(gsl::not_null<pointer> ptr, count_t bytes,
71  align_t alignment) noexcept = 0;
79  virtual auto is_equal(const memory_resource& other) const noexcept -> bool = 0;
80  };
81 
85  auto get_default_memory_resource() noexcept -> memory_resource*;
89  void set_default_memory_resource(gsl::not_null<memory_resource*> p_resource) noexcept;
90 } // namespace caramel
Abstract class defining the interface of a memory resource.
Definition: memory_resource.hpp:23
virtual auto allocate(count_t bytes, align_t alignment) noexcept -> pointer=0
Pure virtual function for a common allocation interface.
virtual auto is_equal(const memory_resource &other) const noexcept -> bool=0
Pure virtual function for a common comparison interface.
virtual void deallocate(gsl::not_null< pointer > ptr, count_t bytes, align_t alignment) noexcept=0
Pure virtual function for a common deallocation interface.
void * pointer
alias for ease of naming
Definition: memory_resource.hpp:25
const void * const_pointer
alias for ease of naming
Definition: memory_resource.hpp:26
Definition: strong_type.hpp:12