OnixS C++ CME MDP Premium Market Data Handler 5.9.0
API Documentation
Loading...
Searching...
No Matches
MemoryPool.h
Go to the documentation of this file.
1// Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2//
3// This software owned by Onix Solutions Limited [OnixS] and is
4// protected by copyright law and international copyright treaties.
5//
6// Access to and use of the software is governed by the terms of the applicable
7// OnixS Software Services Agreement (the Agreement) and Customer end user license
8// agreements granting a non-assignable, non-transferable and non-exclusive license
9// to use the software for it's own data processing purposes under the terms defined
10// in the Agreement.
11//
12// Except as otherwise granted within the terms of the Agreement, copying or
13// reproduction of any part of this source code or associated reference material
14// to any other location for further reproduction or redistribution, and any
15// amendments to this copyright notice, are expressly prohibited.
16//
17// Any reproduction or redistribution for sale or hiring of the Software not in
18// accordance with the terms of the Agreement is a violation of copyright law.
19//
20
21#pragma once
22
23#if defined(ONIXS_CMEMDH_ENABLE_TRACING)
24# include <ostream>
25#endif
26
28
30
36{
37public:
39 virtual void release() = 0;
40
42 virtual void* allocate(size_t) = 0;
43
45 virtual void deallocate(void*) = 0;
46
47#if defined(ONIXS_CMEMDH_ENABLE_TRACING)
48 virtual void trace(std::ostream&) = 0;
49#endif
50
51protected:
57
59 virtual ~MemoryPool() {}
60
61private:
62 // Copies are disallowed.
63 MemoryPool(const MemoryPool&) {}
64
65 // Assignment is disallowed.
66 MemoryPool& operator=(const MemoryPool&)
67 {
68 return *this;
69 }
70};
71
72// Implements STL allocator over MemoryPool.
73template <class Object>
75{
76public:
77 typedef Object value_type;
78 typedef Object* pointer;
79 typedef const Object* const_pointer;
80
81 typedef Object& reference;
82 typedef const Object& const_reference;
83
84 typedef std::size_t size_type;
85 typedef std::ptrdiff_t difference_type;
86
87 template <class Other>
88 struct rebind
89 {
91 };
92
97
102
104 : pool_(other.pool_)
105 {
106 }
107
108 template <class Other>
110 : pool_(&other.memoryPool())
111 {
112 }
113
115
117 {
118 return *pool_;
119 }
120
122 {
123 return &obj;
124 }
125
127 {
128 return &x;
129 }
130
132 {
133 assert(ONIXS_CMEMDH_NULLPTR != pool_);
134
135 return static_cast<pointer>(pool_->allocate(qty * sizeof(value_type)));
136 }
137
139 {
140 assert(ONIXS_CMEMDH_NULLPTR != pool_);
141
142 pool_->deallocate(block);
143 }
144
145 void construct(pointer block, const value_type& obj)
146 {
147 new (block) value_type(obj);
148 }
149
150 void destroy(pointer obj)
151 {
152 obj->~value_type();
153 (void) obj;
154 }
155
157 {
158 return static_cast<size_type>(-1) / sizeof(value_type);
159 }
160
162 {
163 pool_ = other.pool_;
164
165 return *this;
166 }
167
168 template <class Other>
170 {
171 pool_ = &other.memoryPool();
172
173 return *this;
174 }
175
176private:
177 MemoryPool* pool_;
178};
179
180template <class Object, class OtherObject>
182{
183 return (&left.memoryPool() == &right.memoryPool());
184}
185
186template <class Object, class OtherObject>
188{
189 return (&left.memoryPool() != &right.memoryPool());
190}
191
195MemoryPool* makeMemoryPool(size_t, size_t, size_t, size_t);
196
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition Bootstrap.h:67
#define ONIXS_CMEMDH_NAMESPACE_END
Definition Bootstrap.h:68
#define ONIXS_CMEMDH_NULLPTR
Definition Compiler.h:178
#define ONIXS_CMEMDH_EXPORTED
Definition Compiler.h:171
MemoryPoolAllocator(const MemoryPoolAllocator &other)
Definition MemoryPool.h:103
MemoryPoolAllocator(const MemoryPoolAllocator< Other > &other)
Definition MemoryPool.h:109
MemoryPoolAllocator(MemoryPool &memoryPool)
Definition MemoryPool.h:98
const_pointer address(const_reference x) const
Definition MemoryPool.h:126
void deallocate(pointer block, size_type)
Definition MemoryPool.h:138
MemoryPoolAllocator & operator=(const MemoryPoolAllocator< Other > &other)
Definition MemoryPool.h:169
MemoryPoolAllocator & operator=(const MemoryPoolAllocator &other)
Definition MemoryPool.h:161
pointer allocate(size_type qty)
Definition MemoryPool.h:131
void construct(pointer block, const value_type &obj)
Definition MemoryPool.h:145
pointer address(reference obj) const
Definition MemoryPool.h:121
Memory pool abstraction.
Definition MemoryPool.h:36
virtual void deallocate(void *)=0
Releases previously allocated memory block.
virtual ~MemoryPool()
Destruction is through descendants.
Definition MemoryPool.h:59
virtual void release()=0
Releases given instance.
MemoryPool()
Default initialization.
Definition MemoryPool.h:56
virtual void * allocate(size_t)=0
Allocates memory block of given size.
bool operator!=(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition Decimal.h:96
bool operator==(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition Decimal.h:89
MemoryPool * makeMemoryPool(size_t, size_t, size_t, size_t)
Constructs a memory pool instance according to the given configuration.
MemoryPoolAllocator< Other > other
Definition MemoryPool.h:90