7 #include <boost/memory/memory_block.hpp> 11 #include "affix_allocator.hpp" 14 namespace boost {
namespace memory {
16 template <
typename type>
17 inline constexpr std::size_t size_of()
23 inline constexpr std::size_t size_of<void>()
28 template <
typename type>
29 inline void construct_at(memory_block& block, std::size_t offset)
31 new (block + offset) type();
35 inline void construct_at<void>(memory_block& block, std::size_t offset)
39 template <
typename type>
40 inline void destruct_at(memory_block& block, std::size_t offset)
42 reinterpret_cast<type*
>(block + offset)->~type();
46 inline void destruct_at<void>(memory_block& block, std::size_t offset)
51 typename affix_allocator_type>
52 inline affix_allocator_helper<
53 affix_allocator_type>::affix_allocator_helper(affix_allocator_type& instance)
60 typename affix_allocator_type>
61 inline auto& affix_allocator_helper<
62 affix_allocator_type>::get_allocator()
64 return instance_.allocator_;
72 inline memory_block affix_allocator<
78 auto block = allocator_.allocate(size_of_allocation(size));
79 if (block == null_block)
82 construct_prefix(block);
83 construct_suffix(block);
85 return offset_block(block, size);
99 auto original = original_block(block);
100 if (allocator_.owns(original))
104 verify_prefix(original);
105 verify_suffix(original);
108 allocator_.deallocate(original);
124 auto original = original_block(block);
125 return allocator_.owns(original);
137 verify>::size_of_allocation(std::size_t size) noexcept
139 return size + size_of<prefix>() + size_of<suffix>();
151 verify>::offset_block(
memory_block& block, std::size_t size) noexcept
153 return { block + size_of<prefix>(), size };
167 return { block - size_of<prefix>(), block.
size + size_of<prefix>() + size_of<suffix>() };
181 construct_at<prefix>(block, 0ul);
195 construct_at<suffix>(block, block.
size - size_of<suffix>());
209 destruct_at<prefix>(block, 0ul);
223 destruct_at<suffix>(block, block.
size - size_of<suffix>());
void deallocate(memory_block &block)
Deallocates the given memory_block
bool owns(memory_block &block)
Determines if the given memory_block is owned by this allocator.
memory_block allocate(std::size_t size)
Allocates a memory_block with configured affixes.
Allocator adding prefix and suffix objects in boundries of allocated block.
std::size_t size
Block's size.
Represents an allocated memory block.