OnixS C++ CME MDP Premium Market Data Handler  5.8.9
API Documentation
MemoryPoolSettings.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 #include <string>
24 #include <stdexcept>
25 
26 #include <OnixS/CME/MDH/String.h>
27 
29 
30 /// Raises exception on zero parameter value.
31 inline void throwZeroParameter(const Char* parameter)
32 {
33  std::string reason;
34 
35  reason += "Non-zero value is expected for '";
36  reason += parameter ? parameter : "<unknown>";
37  reason += "' parameter. ";
38 
39  throw std::out_of_range(reason);
40 }
41 
42 /// Memory pool settings.
43 ///
44 /// Control parameters affecting behavior of memory
45 /// pool used by Handler while processing market data.
47 {
48 public:
49  /// Initializes parameters with default values.
51  : blockIncrease_(48)
52  , increaseQty_(32)
53  , chunkSize_(20)
54  , chunkScaling_(2)
55  {
56  }
57 
58  /// Initializes as a copy.
60  : blockIncrease_(other.blockIncrease_)
61  , increaseQty_(other.increaseQty_)
62  , chunkSize_(other.chunkSize_)
63  , chunkScaling_(other.chunkScaling_)
64  {
65  }
66 
67  /// Finalizes the instance.
69 
70  /// Memory block increase value.
71  ///
72  /// Memory pool allocates blocks
73  /// divisible by given value.
74  size_t blockIncrease() const
75  {
76  return blockIncrease_;
77  }
78 
79  /// Updates memory block increase value.
80  ///
81  /// Memory pool allocates blocks
82  /// divisible by given value.
83  void blockIncrease(size_t increase)
84  {
85  const Char* const name = "BlockIncrease";
86 
87  if (0 < increase)
88  {
89  blockIncrease_ = increase;
90  }
91  else
92  {
93  throwZeroParameter(name);
94  }
95  }
96 
97  /// Limits number of increases memory pool does.
98  ///
99  /// Memory pool allocates blocks divisible by
100  /// 'blockIncrease' value. Efficient allocation
101  /// is performed for blocks whose size doesn't
102  /// exceeds multiplication of 'blockIncrease'
103  /// and 'increaseQty' values. Other blocks are
104  /// allocated upon request without caching.
105  size_t increaseQty() const
106  {
107  return increaseQty_;
108  }
109 
110  /// Limits number of increases memory pool does.
111  ///
112  /// Memory pool allocates blocks divisible by
113  /// 'blockIncrease' value. Efficient allocation
114  /// is performed for blocks whose size doesn't
115  /// exceeds multiplication of 'blockIncrease'
116  /// and 'increaseQty' values. Other blocks are
117  /// allocated upon request without caching.
118  void increaseQty(size_t qty)
119  {
120  const Char* const name = "IncreaseQty";
121 
122  if (0 < qty)
123  {
124  increaseQty_ = qty;
125  }
126  else
127  {
128  throwZeroParameter(name);
129  }
130  }
131 
132  /// Number of blocks per chunk.
133  ///
134  /// Memory pool allocates chunks of blocks
135  /// thus reducing number of actual allocations.
136  /// Given parameter specifies number of memory
137  /// blocks of same size allocated at once if
138  /// pool is empty.
139  size_t chunkSize() const
140  {
141  return chunkSize_;
142  }
143 
144  /// Number of blocks per chunk.
145  ///
146  /// Memory pool allocates chunks of blocks
147  /// thus reducing number of actual allocations.
148  /// Given parameter specifies number of memory
149  /// blocks of same size allocated at once if
150  /// pool is empty.
151  void chunkSize(size_t size)
152  {
153  const Char* const name = "ChunkSize";
154 
155  if (0 < size)
156  {
157  chunkSize_ = size;
158  }
159  else
160  {
161  throwZeroParameter(name);
162  }
163  }
164 
165  /// Defines chunk scale factor.
166  ///
167  /// Each time memory pool allocates a new chunk
168  /// of blocks, its size is scaled by given factor.
169  size_t chunkScaling() const
170  {
171  return chunkScaling_;
172  }
173 
174  /// Defines chunk scale factor.
175  ///
176  /// Each time memory pool allocates a new chunk
177  /// of blocks, its size is scaled by given factor.
178  void chunkScaling(size_t factor)
179  {
180  const Char* const name = "ChunkScaling";
181 
182  if (0 < factor)
183  {
184  chunkScaling_ = factor;
185  }
186  else
187  {
188  throwZeroParameter(name);
189  }
190  }
191 
192  /// Initializes as a copy.
194  {
195  blockIncrease_ = other.blockIncrease_;
196 
197  increaseQty_ = other.increaseQty_;
198 
199  chunkSize_ = other.chunkSize_;
200 
201  chunkScaling_ = other.chunkScaling_;
202 
203  return *this;
204  }
205 
206 private:
207  size_t blockIncrease_;
208 
209  size_t increaseQty_;
210 
211  size_t chunkSize_;
212 
213  size_t chunkScaling_;
214 };
215 
216 /// Serializes memory pool settings into a string.
218 void toStr(std::string&, const MemoryPoolSettings&);
219 
220 /// Serializes memory pool settings into a string.
221 inline std::string toStr(const MemoryPoolSettings& settings)
222 {
223  std::string str;
224 
225  toStr(str, settings);
226 
227  return str;
228 }
229 
size_t blockIncrease() const
Memory block increase value.
std::string toStr(const MemoryPoolSettings &settings)
Serializes memory pool settings into a string.
#define ONIXS_CMEMDH_LTWT
Definition: Bootstrap.h:46
void blockIncrease(size_t increase)
Updates memory block increase value.
char Char
Character type alias.
Definition: String.h:36
MemoryPoolSettings & operator=(const MemoryPoolSettings &other)
Initializes as a copy.
MemoryPoolSettings()
Initializes parameters with default values.
void chunkScaling(size_t factor)
Defines chunk scale factor.
size_t increaseQty() const
Limits number of increases memory pool does.
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:67
void chunkSize(size_t size)
Number of blocks per chunk.
~MemoryPoolSettings()
Finalizes the instance.
#define ONIXS_CMEMDH_EXPORTED
Definition: Compiler.h:160
size_t chunkSize() const
Number of blocks per chunk.
size_t chunkScaling() const
Defines chunk scale factor.
void throwZeroParameter(const Char *parameter)
Raises exception on zero parameter value.
void increaseQty(size_t qty)
Limits number of increases memory pool does.
MemoryPoolSettings(const MemoryPoolSettings &other)
Initializes as a copy.
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:68