OnixS C++ CME MDP Streamlined Market Data Handler  1.2.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 
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  /// Memory block increase value.
70  ///
71  /// Memory pool allocates blocks divisible by given value.
72  size_t blockIncrease() const
73  {
74  return blockIncrease_;
75  }
76 
77  /// Updates memory block increase value.
78  ///
79  /// Memory pool allocates blocks divisible by given value.
80  void
82  size_t increase)
83  {
84  if (0 < increase)
85  {
86  blockIncrease_ = increase;
87  }
88  else
89  {
90  throwZeroParameter("blockIncrease");
91  }
92  }
93 
94  /// Limits number of increases memory pool does.
95  ///
96  /// Memory pool allocates blocks divisible by 'blockIncrease' value.
97  /// Efficient allocation is performed for blocks whose size doesn't
98  /// exceeds multiplication of 'blockIncrease' and 'increaseQty' values.
99  /// Other blocks are allocated upon request without caching.
100  size_t increaseQty() const
101  {
102  return increaseQty_;
103  }
104 
105  /// Limits number of increases memory pool does.
106  ///
107  /// Memory pool allocates blocks divisible by 'blockIncrease' value.
108  /// Efficient allocation is performed for blocks whose size doesn't
109  /// exceeds multiplication of 'blockIncrease' and 'increaseQty' values.
110  /// Other blocks are allocated upon request without caching.
111  void
113  size_t qty)
114  {
115  if (0 < qty)
116  {
117  increaseQty_ = qty;
118  }
119  else
120  {
121  throwZeroParameter("increaseQty");
122  }
123  }
124 
125  /// Number of blocks per chunk.
126  ///
127  /// Memory pool allocates chunks of blocks thus reducing
128  /// number of actual allocations. Given parameter specifies
129  /// number of memory blocks of same size allocated at once
130  /// if pool is empty.
131  size_t chunkSize() const
132  {
133  return chunkSize_;
134  }
135 
136  /// Number of blocks per chunk.
137  ///
138  /// Memory pool allocates chunks of blocks thus reducing
139  /// number of actual allocations. Given parameter specifies
140  /// number of memory blocks of same size allocated at once
141  /// if pool is empty.
142  void
144  size_t size)
145  {
146  if (0 < size)
147  {
148  chunkSize_ = size;
149  }
150  else
151  {
152  throwZeroParameter("chunkSize");
153  }
154  }
155 
156  /// Defines chunk scale factor.
157  ///
158  /// Each time memory pool allocates a new chunk
159  /// of blocks, its size is scaled by given factor.
160  size_t chunkScaling() const
161  {
162  return chunkScaling_;
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  void
171  size_t factor)
172  {
173  if (0 < factor)
174  {
175  chunkScaling_ = factor;
176  }
177  else
178  {
179  throwZeroParameter("chunkScaling");
180  }
181  }
182 };
183 
184 /// Serializes memory pool settings into a string.
186 void
187 toStr(
188  std::string&,
189  const
191 
192 /// Serializes memory pool settings into a string.
193 inline
194 std::string
196  const
197  MemoryPoolSettings& settings)
198 {
199  std::string str;
200 
201  toStr(str, settings);
202 
203  return str;
204 }
205 
void chunkSize(size_t size)
Number of blocks per chunk.
void increaseQty(size_t qty)
Limits number of increases memory pool does.
size_t blockIncrease() const
Memory block increase value.
#define ONIXS_CMESTREAMLINEDMDH_NAMESPACE_END
Definition: Bootstrap.h:173
#define ONIXS_CMESTREAMLINEDMDH_LTWT_CLASS
Definition: Bootstrap.h:111
#define ONIXS_CMESTREAMLINEDMDH_EXPORTED
Definition: Compiler.h:160
void chunkScaling(size_t factor)
Defines chunk scale factor.
size_t increaseQty() const
Limits number of increases memory pool does.
MemoryPoolSettings()
Initializes parameters with default values.
size_t chunkScaling() const
Defines chunk scale factor.
std::string toStr(const MemoryPoolSettings &settings)
Serializes memory pool settings into a string.
size_t chunkSize() const
Number of blocks per chunk.
void blockIncrease(size_t increase)
Updates memory block increase value.
void throwZeroParameter(const char *parameter)
Raises exception on zero parameter value.
#define ONIXS_CMESTREAMLINEDMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:169