Sources Pipelines Documentation

Allocators  
segregator.ipp
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 
8 namespace boost { namespace memory {
9 
10 template <
11  std::size_t threshold,
12  typename primary_allocator,
13  typename secondary_allocator>
14 inline memory_block segregator<
15  threshold,
16  primary_allocator,
17  secondary_allocator>::allocate(std::size_t size)
18 {
19  if (size <= threshold)
20  return primary_.allocate(size);
21  else
22  return secondary_.allocate(size);
23 }
24 
25 template <
26  std::size_t threshold,
27  typename primary_allocator,
28  typename secondary_allocator>
29 inline void segregator<
30  threshold,
31  primary_allocator,
32  secondary_allocator>::deallocate(memory_block& block)
33 {
34  if (block.size <= threshold)
35  primary_.deallocate(block);
36  else
37  secondary_.deallocate(block);
38 }
39 
40 template <
41  std::size_t threshold,
42  typename primary_allocator,
43  typename secondary_allocator>
44 inline bool segregator<
45  threshold,
46  primary_allocator,
47  secondary_allocator>::owns(memory_block& block)
48 {
49  return block.size <= threshold ? primary_.owns(block) : secondary_.owns(block);
50 }
51 
52 template <
53  std::size_t threshold,
54  typename primary_allocator,
55  typename secondary_allocator>
56 inline primary_allocator& segregator<
57  threshold,
58  primary_allocator,
59  secondary_allocator>::get_primary() noexcept
60 {
61  return primary_;
62 }
63 
64 template <
65  std::size_t threshold,
66  typename primary_allocator,
67  typename secondary_allocator>
68 inline secondary_allocator& segregator<
69  threshold,
70  primary_allocator,
71  secondary_allocator>::get_secondary() noexcept
72 {
73  return secondary_;
74 }
75 
76 } }
void deallocate(memory_block &block)
Deallocates the given memory_block if possible.
Definition: segregator.ipp:32
std::size_t size
Block&#39;s size.
Represents an allocated memory block.
Segregates allocation strategies according to the given allocation size threshold.
Definition: segregator.hpp:31