Sources Pipelines Documentation

Allocators  
bucketizer.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 #include <iterator>
10 
11 
12 namespace boost { namespace memory {
13 
14 template <typename bucketizer_type>
15 class bucketizer_helper final
16 {
17 public:
18  bucketizer_helper(bucketizer_type& instance);
19 
20  template <std::size_t bucket>
21  auto& get() noexcept;
22 
23 private:
24  bucketizer_type& instance_;
25 };
26 
27 template <
28  typename allocator,
29  std::size_t min,
30  std::size_t max,
31  std::size_t step>
33 {
34 public:
35  using allocator_type = allocator;
36 
37  static const std::size_t buckets_count = (max - min) / step;
38  static const std::size_t min_size = min;
39  static const std::size_t max_size = max;
40  static const std::size_t step_size = step;
41 
42  memory_block allocate(std::size_t size);
43  void deallocate(memory_block& block);
44 
45  bool owns(memory_block& block);
46 
47 private:
49  friend bucketizer_helper<this_bucketizer_type>;
50 
51  allocator buckets_[(max - min) / step];
52 };
53 
54 } }
55 
56 #include "bucketizer.ipp"
Represents an allocated memory block.