bit::memory
null_block_allocator.hpp
1 /*****************************************************************************
2  * \file
3  * \brief This header defines the null block allocator, null_block_allocator
4  *****************************************************************************/
5 
6 /*
7  The MIT License (MIT)
8 
9  Copyright (c) 2018 Matthew Rodusek
10 
11  Permission is hereby granted, free of charge, to any person obtaining a copy
12  of this software and associated documentation files (the "Software"), to deal
13  in the Software without restriction, including without limitation the rights
14  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  copies of the Software, and to permit persons to whom the Software is
16  furnished to do so, subject to the following conditions:
17 
18  The above copyright notice and this permission notice shall be included in
19  all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  SOFTWARE.
28 */
29 #ifndef BIT_MEMORY_BLOCK_ALLOCATORS_NULL_BLOCK_ALLOCATOR_HPP
30 #define BIT_MEMORY_BLOCK_ALLOCATORS_NULL_BLOCK_ALLOCATOR_HPP
31 
32 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
33 # pragma once
34 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
35 
36 #include "detail/named_block_allocator.hpp" // detail::named_block_allocator
37 
38 #include "../utilities/allocator_info.hpp" // allocator_info
39 #include "../utilities/macros.hpp" // BIT_MEMORY_UNLIKELY
40 #include "../utilities/memory_block.hpp" // memory_block
41 #include "../utilities/owner.hpp" // owner
42 
43 #include <type_traits> // std::integral_constant, std::true_false
44 #include <cstddef> // std::max_align_t
45 
46 namespace bit {
47  namespace memory {
48 
56  {
57  //----------------------------------------------------------------------
58  // Public Member Types
59  //----------------------------------------------------------------------
60  public:
61 
62  using default_block_alignment = std::integral_constant<std::size_t,1>;
63 
64  //-----------------------------------------------------------------------
65  // Constructor / Assignment
66  //-----------------------------------------------------------------------
67  public:
68 
70  null_block_allocator() = default;
71 
75  null_block_allocator( null_block_allocator&& other ) noexcept = default;
76 
80  null_block_allocator( const null_block_allocator& other ) noexcept = default;
81 
82  //-----------------------------------------------------------------------
83 
88  null_block_allocator& operator=( null_block_allocator&& other ) noexcept = default;
89 
94  null_block_allocator& operator=( const null_block_allocator& other ) noexcept = default;
95 
96  //----------------------------------------------------------------------
97  // Block Allocations
98  //----------------------------------------------------------------------
99  public:
100 
104  owner<memory_block> allocate_block() noexcept;
105 
109  void deallocate_block( owner<memory_block> block ) noexcept;
110 
111  //-----------------------------------------------------------------------
112  // Observers
113  //-----------------------------------------------------------------------
114  public:
115 
119  std::size_t next_block_size() const noexcept;
120 
127  allocator_info info() const noexcept;
128  };
129 
130  //-------------------------------------------------------------------------
131  // Utilities
132  //-------------------------------------------------------------------------
133 
134  using named_null_block_allocator = detail::named_block_allocator<null_block_allocator>;
135 
136  } // namespace memory
137 } // namespace bit
138 
139 #include "detail/null_block_allocator.inl"
140 
141 #endif /* BIT_MEMORY_BLOCK_ALLOCATORS_NULL_BLOCK_ALLOCATOR_HPP */
null_block_allocator()=default
Default-constructs a null_block_allocator.
A block allocator that only distributes null blocks.
allocator_info info() const noexcept
Gets the info about this allocator.
std::size_t next_block_size() const noexcept
Queries the next block size expected from this allocator.
void deallocate_block(owner< memory_block > block) noexcept
Deallocates a memory_block.
owner< memory_block > allocate_block() noexcept
Allocates a null memory_block.
This type is used to hold the generic information for a given allocator.
null_block_allocator & operator=(null_block_allocator &&other) noexcept=default
Move-assigns a null_block_allocator from another allocator.