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