#ifndef __INC_ETERLIB_BUFFERPOOL_H__ #define __INC_ETERLIB_BUFFERPOOL_H__ #include #include #include // Buffer pool for file I/O operations class CBufferPool { public: CBufferPool(); ~CBufferPool(); // Get buffer with minimum size std::vector Acquire(size_t minSize); // Return buffer to pool void Release(std::vector&& buffer); // Get statistics size_t GetPoolSize() const; size_t GetTotalAllocated() const; size_t GetTotalMemoryPooled() const; // Total bytes held in pool // Clear pool void Clear(); private: struct TPooledBuffer { std::vector buffer; size_t capacity; TPooledBuffer(std::vector&& buf) : buffer(std::move(buf)) , capacity(buffer.capacity()) { } }; std::vector m_pool; mutable std::mutex m_mutex; size_t m_totalAllocated; static const size_t MAX_POOL_SIZE = 64; static const size_t MAX_BUFFER_SIZE = 64 * 1024 * 1024; }; #endif // __INC_ETERLIB_BUFFERPOOL_H__