// Copyright (C) 2021 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_CORE_MEMORYPOOL_HPP #define NAZARA_CORE_MEMORYPOOL_HPP #include #include #include namespace Nz { class MemoryPool { public: MemoryPool(unsigned int blockSize, unsigned int size = 1024, bool canGrow = true); MemoryPool(const MemoryPool&) = delete; MemoryPool(MemoryPool&& pool) noexcept; ~MemoryPool() = default; void* Allocate(unsigned int size); template void Delete(T* ptr); void Free(void* ptr); inline unsigned int GetBlockSize() const; inline unsigned int GetFreeBlocks() const; inline unsigned int GetSize() const; template T* New(Args&&... args); MemoryPool& operator=(const MemoryPool&) = delete; MemoryPool& operator=(MemoryPool&& pool) noexcept; private: MemoryPool(MemoryPool* pool); std::unique_ptr m_freeList; std::unique_ptr m_pool; std::unique_ptr m_next; std::atomic_uint m_freeCount; MemoryPool* m_previous; bool m_canGrow; unsigned int m_blockSize; unsigned int m_size; }; } #include #endif // NAZARA_CORE_MEMORYPOOL_HPP