OnixS C++ CME MDP Streamlined Market Data Handler 1.2.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_CMESTREAMLINEDMDH_ENABLE_TRACING)
24#include <ostream>
25#endif
26
27#include <cassert>
28
30
32
38{
39 // Copies are disallowed.
40 MemoryPool(
41 const MemoryPool&)
42 {
43 }
44
45 // Assignment is disallowed.
46 MemoryPool&
47 operator =(
48 const MemoryPool&)
49 {
50 return *this;
51 }
52
53protected:
59 {
60 }
61
63 virtual ~MemoryPool()
64 {
65 }
66
67public:
69 virtual void release() = 0;
70
72 virtual void* allocate(size_t) = 0;
73
75 virtual void deallocate(void*) = 0;
76
77#if defined(ONIXS_CMESTREAMLINEDMDH_ENABLE_TRACING)
78 virtual void trace(std::ostream&) = 0;
79#endif
80};
81
82// Implements STL allocator over MemoryPool.
83template
84<
85 class Object
86>
88{
89 MemoryPool* pool_;
90
91public:
92 typedef Object value_type;
93 typedef Object* pointer;
94 typedef const Object* const_pointer;
95
96 typedef Object& reference;
97 typedef const Object& const_reference;
98
99 typedef std::size_t size_type;
100 typedef std::ptrdiff_t difference_type;
101
102 template
103 <
104 class Other
105 >
106 struct rebind
107 {
108 typedef
111 };
112
117
120 : pool_(&memoryPool)
121 {
122 }
123
125 const MemoryPoolAllocator& other)
126 : pool_(other.pool_)
127 {
128 }
129
130 template
131 <
132 class Other
133 >
135 const MemoryPoolAllocator<Other>& other)
136 : pool_(&other.memoryPool())
137 {
138 }
139
141 {
142 }
143
145 {
146 return *pool_;
147 }
148
149 pointer
151 reference obj) const
152 {
153 return &obj;
154 }
155
156 const_pointer
158 const_reference x) const
159 {
160 return &x;
161 }
162
163 pointer
165 size_type qty)
166 {
167 assert(ONIXS_CMESTREAMLINEDMDH_NULLPTR != pool_);
168
169 return static_cast<pointer>
170 (
171 pool_->allocate
172 (
173 qty * sizeof(value_type)
174 )
175 );
176 }
177
178 void
180 pointer block,
181 size_type)
182 {
183 assert(ONIXS_CMESTREAMLINEDMDH_NULLPTR != pool_);
184
185 pool_->deallocate(block);
186 }
187
188 void
190 pointer block,
191 const value_type& obj)
192 {
193 new (block) value_type(obj);
194 }
195
196 void
198 pointer obj)
199 {
200 obj->~value_type();
201 }
202
204 {
205 return
206 static_cast<size_type>(-1) /
207 sizeof(value_type);
208 }
209
211 operator =(
212 const MemoryPoolAllocator& other)
213 {
214 pool_ = other.pool_;
215
216 return *this;
217 }
218
219 template
220 <
221 class Other
222 >
224 operator =(
225 const MemoryPoolAllocator<Other>& other)
226 {
227 pool_ = &other.memoryPool();
228
229 return *this;
230 }
231};
232
233template
234<
235 class Object,
236 class OtherObject
237>
238inline
239bool
240operator ==(
241 const MemoryPoolAllocator<Object>& left,
243{
244 return
245 (
246 &left.memoryPool() == &right.memoryPool()
247 );
248}
249
250template
251<
252 class Object,
253 class OtherObject
254>
255inline
256bool
257operator !=(
258 const MemoryPoolAllocator<Object>& left,
260{
261 return
262 (
263 &left.memoryPool() != &right.memoryPool()
264 );
265}
266
270MemoryPool*
272 size_t, size_t, size_t, size_t);
273
#define ONIXS_CMESTREAMLINEDMDH_EXPORTED_CLASS
Definition Bootstrap.h:63
#define ONIXS_CMESTREAMLINEDMDH_NAMESPACE_BEGIN
Definition Bootstrap.h:169
#define ONIXS_CMESTREAMLINEDMDH_NAMESPACE_END
Definition Bootstrap.h:173
#define ONIXS_CMESTREAMLINEDMDH_EXPORTED
Definition Compiler.h:160
#define ONIXS_CMESTREAMLINEDMDH_NULLPTR
Definition Compiler.h:167
MemoryPoolAllocator(const MemoryPoolAllocator &other)
Definition MemoryPool.h:124
MemoryPoolAllocator(const MemoryPoolAllocator< Other > &other)
Definition MemoryPool.h:134
const_pointer address(const_reference x) const
Definition MemoryPool.h:157
void deallocate(pointer block, size_type)
Definition MemoryPool.h:179
void construct(pointer block, const value_type &obj)
Definition MemoryPool.h:189
virtual void deallocate(void *)=0
Releases previously allocated memory block.
virtual ~MemoryPool()
Destruction is through descendants.
Definition MemoryPool.h:63
virtual void release()=0
Releases given instance.
MemoryPool()
Default initialization.
Definition MemoryPool.h:58
virtual void * allocate(size_t)=0
Allocates memory block of given size.
MemoryPool * makeMemoryPool(size_t, size_t, size_t, size_t)
Constructs memory pool instance according to given configuration.