Sources Pipelines Documentation

Allocators  
All Classes Functions Variables
stack_allocator.hpp
1 // Copyright (c) 2016 Lukasz Laszko
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 #pragma once
6 
7 #include <boost/memory/alignment.hpp>
8 #include <boost/memory/memory_block.hpp>
9 #include <boost/memory/null_allocator.hpp>
10 
11 #include <cstdint>
12 
13 
14 namespace boost { namespace memory {
15 
23 template <std::size_t capacity, std::size_t alignment=NO_ALIGNMENT>
25 {
26 public:
37  memory_block allocate(std::size_t size);
38 
43  void deallocate(memory_block& block);
44 
50  bool owns(memory_block& block) const noexcept;
51 
52 private:
53  std::uint8_t reserved_block_[capacity];
54  std::uint8_t* current_ { align_forward<alignment>(reserved_block_) };
55 };
56 
57 } }
58 
59 #include "stack_allocator.ipp"
60 
bool owns(memory_block &block) const noexcept
Determines if the block has been allocated with this allocator.
void deallocate(memory_block &block)
Deallocates the block if possible.
Allocates memory block from a fixed range reserved from the current execution stack.
memory_block allocate(std::size_t size)
Allocated a block of the requested size on the stack.
Represents an allocated memory block.