Sources Pipelines Documentation

Allocators  
fallback_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/memory_block.hpp>
8 
9 
10 namespace boost { namespace memory {
11 
24 template <
25  typename primary_allocator,
26  typename secondary_allocator>
27 class fallback_allocator final
28 {
29 public:
47  memory_block allocate(std::size_t size);
48 
59  void deallocate(memory_block& block);
60 
71  bool owns(memory_block& block);
72 
73  primary_allocator& get_primary() noexcept;
74  secondary_allocator& get_secondary() noexcept;
75 
76 private:
77  primary_allocator primary_;
78  secondary_allocator secondary_;
79 };
80 
81 } }
82 
83 #include "fallback_allocator.ipp"
84 
Allocates with secondary allocator, if allocation with primary allocator fails.
bool owns(memory_block &block)
Examines if the given block is owned by this allocator.
void deallocate(memory_block &block)
Deallocates the given memory_block.
Represents an allocated memory block.
memory_block allocate(std::size_t size)
Allocates a memory_block with either primary_allocator or secondary_allocator.