// Copyright Onix Solutions Limited [OnixS]. All rights reserved. // // This software owned by Onix Solutions Limited [OnixS] and is // protected by copyright law and international copyright treaties. // // Access to and use of the software is governed by the terms of the applicable // OnixS Software Services Agreement (the Agreement) and Customer end user license // agreements granting a non-assignable, non-transferable and non-exclusive license // to use the software for it's own data processing purposes under the terms defined // in the Agreement. // // Except as otherwise granted within the terms of the Agreement, copying or // reproduction of any part of this source code or associated reference material // to any other location for further reproduction or redistribution, and any // amendments to this copyright notice, are expressly prohibited. // // Any reproduction or redistribution for sale or hiring of the Software not in // accordance with the terms of the Agreement is a violation of copyright law. // #pragma once #include #include #include ONIXS_CMEMDH_NAMESPACE_BEGIN /// Raises exception on zero parameter value. inline void throwZeroParameter( const char* parameter) { std::string reason; reason += "Non-zero value is expected for '"; reason += parameter ? parameter : ""; reason += "' parameter. "; throw std::out_of_range(reason); } /// Memory pool settings. /// /// Control parameters affecting behavior of memory /// pool used by Handler while processing market data. ONIXS_CMEMDH_LTWT_CLASS MemoryPoolSettings { size_t blockIncrease_; size_t increaseQty_; size_t chunkSize_; size_t chunkScaling_; public: /// Initializes parameters with default values. MemoryPoolSettings() : blockIncrease_(48) , increaseQty_(32) , chunkSize_(20) , chunkScaling_(2) { } /// Memory block increase value. /// /// Memory pool allocates blocks divisible by given value. size_t blockIncrease() const { return blockIncrease_; } /// Updates memory block increase value. /// /// Memory pool allocates blocks divisible by given value. void blockIncrease( size_t increase) { if (0 < increase) { blockIncrease_ = increase; } else { throwZeroParameter("blockIncrease"); } } /// Limits number of increases memory pool does. /// /// Memory pool allocates blocks divisible by 'blockIncrease' value. /// Efficient allocation is performed for blocks whose size doesn't /// exceeds multiplication of 'blockIncrease' and 'increaseQty' values. /// Other blocks are allocated upon request without caching. size_t increaseQty() const { return increaseQty_; } /// Limits number of increases memory pool does. /// /// Memory pool allocates blocks divisible by 'blockIncrease' value. /// Efficient allocation is performed for blocks whose size doesn't /// exceeds multiplication of 'blockIncrease' and 'increaseQty' values. /// Other blocks are allocated upon request without caching. void increaseQty( size_t qty) { if (0 < qty) { increaseQty_ = qty; } else { throwZeroParameter("increaseQty"); } } /// Number of blocks per chunk. /// /// Memory pool allocates chunks of blocks thus reducing /// number of actual allocations. Given parameter specifies /// number of memory blocks of same size allocated at once /// if pool is empty. size_t chunkSize() const { return chunkSize_; } /// Number of blocks per chunk. /// /// Memory pool allocates chunks of blocks thus reducing /// number of actual allocations. Given parameter specifies /// number of memory blocks of same size allocated at once /// if pool is empty. void chunkSize( size_t size) { if (0 < size) { chunkSize_ = size; } else { throwZeroParameter("chunkSize"); } } /// Defines chunk scale factor. /// /// Each time memory pool allocates a new chunk /// of blocks, its size is scaled by given factor. size_t chunkScaling() const { return chunkScaling_; } /// Defines chunk scale factor. /// /// Each time memory pool allocates a new chunk /// of blocks, its size is scaled by given factor. void chunkScaling( size_t factor) { if (0 < factor) { chunkScaling_ = factor; } else { throwZeroParameter("chunkScaling"); } } }; /// Serializes memory pool settings into a string. ONIXS_CMEMDH_EXPORTED void toStr( std::string&, const MemoryPoolSettings&); /// Serializes memory pool settings into a string. inline std::string toStr( const MemoryPoolSettings& settings) { std::string str; toStr(str, settings); return str; } ONIXS_CMEMDH_NAMESPACE_END