/** * @file include/ActivMiddleware/Misc/FixedMemoryPool.h * * @brief Implements the FixedMemoryPool class. */ #if (!defined ACTIV_MISC_FIXED_MEMORY_POOL_H) #define ACTIV_MISC_FIXED_MEMORY_POOL_H #include ACTIV_BOOST_INCLUDE(pool/simple_segregated_storage.hpp) //! Activ namespace. namespace Activ { /** * @brief Fixed memory pool class. * * Provides a minimally compatible interface to Boost::pool to an area of user allocated memory. * * See the Boost::pool documentation for methods not documented below. */ template class FixedMemoryPool { public: /** * @brief Constructor. * * Initializes the pool with chunks cut from the user supplied memory. * * @param pMemory * @param size * @param requestedSize */ FixedMemoryPool(void *pMemory, const SizeType size, SizeType requestedSize) : m_requestedSize(requestedSize) { m_storage.add_block(pMemory, size, requestedSize); } SizeType get_requested_size() const { return m_requestedSize; } void *malloc() { if (!m_storage.empty()) return m_storage.malloc(); else return 0; } void free(void *chunk) { assert(0 != chunk); m_storage.free(chunk); } private: Boost::simple_segregated_storage m_storage; SizeType m_requestedSize; }; } // namespace Activ #endif // (!defined ACTIV_MISC_FIXED_MEMORY_POOL_H)