QuantumLibrary
quantum_stack_allocator.h
1 /*
2 ** Copyright 2018 Bloomberg Finance L.P.
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 #ifndef BLOOMBERG_QUANTUM_STACK_ALLOCATOR_H
17 #define BLOOMBERG_QUANTUM_STACK_ALLOCATOR_H
18 
19 #include <quantum/quantum_contiguous_pool_manager.h>
20 
21 namespace Bloomberg {
22 namespace quantum {
23 
24 //==============================================================================
25 // struct StackAllocator
26 //==============================================================================
33 template <typename T, unsigned int SIZE>
35 {
36  //------------------------------ Typedefs ----------------------------------
38  typedef T value_type;
39  typedef value_type* pointer;
40  typedef const value_type* const_pointer;
42  typedef const value_type& const_reference;
43  typedef size_t size_type;
44  typedef std::ptrdiff_t difference_type;
45  typedef std::false_type propagate_on_container_move_assignment;
46  typedef std::false_type propagate_on_container_copy_assignment;
47  typedef std::false_type propagate_on_container_swap;
48  typedef std::false_type is_always_equal;
49  typedef std::true_type default_constructor;
50  typedef std::aligned_storage<sizeof(value_type),
52  typedef typename storage_type::type aligned_type;
53 
54  template <typename U>
55  struct rebind
56  {
58  };
59  //------------------------------- Methods ----------------------------------
60  StackAllocator() : ContiguousPoolManager<T>(_buffer, SIZE)
61  {}
63  {}
65  {}
67  return StackAllocator();
68  }
69  template <typename U>
71  {}
72  template <typename U>
74  {}
75  bool operator==(const this_type&) const {
76  return false;
77  }
78  bool operator!=(const this_type&) const {
79  return true;
80  }
81 
82 private:
83  //------------------------------- Members ----------------------------------
84  aligned_type _buffer[SIZE];
85 };
86 
87 }} //namespaces
88 
89 #endif //BLOOMBERG_QUANTUM_STACK_ALLOCATOR_H
Provides fast (quasi zero-time) in-place allocation for STL containers. Objects are allocated from a ...
Definition: quantum_contiguous_pool_manager.h:40
Definition: quantum_buffer_impl.h:22
static StackAllocator select_on_container_copy_construction(const StackAllocator &)
Definition: quantum_stack_allocator.h:66
StackAllocator(const this_type &)
Definition: quantum_stack_allocator.h:62
std::ptrdiff_t difference_type
Definition: quantum_stack_allocator.h:44
StackAllocator(const StackAllocator< U, SIZE > &)
Definition: quantum_stack_allocator.h:70
value_type & reference
Definition: quantum_stack_allocator.h:41
bool operator==(const this_type &) const
Definition: quantum_stack_allocator.h:75
std::true_type default_constructor
Definition: quantum_stack_allocator.h:49
StackAllocator & operator=(const StackAllocator< U, SIZE > &)
Definition: quantum_stack_allocator.h:73
value_type * pointer
Definition: quantum_stack_allocator.h:39
StackAllocator< U, SIZE > other
Definition: quantum_stack_allocator.h:57
Provides a stack-based object pool to the underlying ContiguousPoolManager. The default buffer size i...
Definition: quantum_stack_allocator.h:34
T value_type
Definition: quantum_stack_allocator.h:38
T value_type
Definition: quantum_contiguous_pool_manager.h:44
StackAllocator & operator=(const this_type &)
Definition: quantum_stack_allocator.h:64
StackAllocator()
Definition: quantum_stack_allocator.h:60
const value_type * const_pointer
Definition: quantum_stack_allocator.h:40
std::false_type is_always_equal
Definition: quantum_stack_allocator.h:48
bool operator!=(const this_type &) const
Definition: quantum_stack_allocator.h:78
std::false_type propagate_on_container_swap
Definition: quantum_stack_allocator.h:47
Definition: quantum_stack_allocator.h:55
StackAllocator< T, SIZE > this_type
Definition: quantum_stack_allocator.h:37
std::false_type propagate_on_container_copy_assignment
Definition: quantum_stack_allocator.h:46
std::aligned_storage< sizeof(value_type), alignof(value_type)> storage_type
Definition: quantum_stack_allocator.h:51
std::false_type propagate_on_container_move_assignment
Definition: quantum_stack_allocator.h:45
size_t size_type
Definition: quantum_stack_allocator.h:43
storage_type::type aligned_type
Definition: quantum_stack_allocator.h:52
const value_type & const_reference
Definition: quantum_stack_allocator.h:42