Added MemoryPool class

Former-commit-id: cc704583a686dd631bee54ed48cee913aeb2e369
This commit is contained in:
Lynix
2014-05-28 10:02:43 +02:00
parent df803fd5f7
commit c27187ae4b
2 changed files with 123 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
// Copyright (C) 2014 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_MEMORYPOOL_HPP
#define NAZARA_MEMORYPOOL_HPP
#include <Nazara/Prerequesites.hpp>
#include <memory>
template<unsigned int typeSize, unsigned int count = 1000, bool canGrow = true>
class NzMemoryPool
{
public:
NzMemoryPool();
~NzMemoryPool() = default;
template<typename T> T* Allocate();
void* Allocate(unsigned int size);
void Free(void* ptr);
private:
NzMemoryPool(NzMemoryPool* pool);
std::unique_ptr<void*[]> m_freeList;
std::unique_ptr<nzUInt8[]> m_pool;
std::unique_ptr<NzMemoryPool> m_next;
NzMemoryPool* m_previous;
unsigned int m_freeCount;
};
#include <Nazara/Core/MemoryPool.inl>
#endif // NAZARA_MEMORYPOOL_HPP