scummvm/common/memorypool.h
Bertrand Augereau 411a588850 Introduction of a fixed size memory pool with a typical free list implementation
+ : amortized O(1) allocation, O(1) deallocation, less overhead per allocation
- : unused memory is not reclaimed until death or manual invocation of a function

svn-id: r31320
2008-03-30 05:42:39 +00:00

34 lines
515 B
C++

#ifndef COMMON_MEMORYPOOL_H
#define COMMON_MEMORYPOOL_H
#include <cstring>
#include "common/array.h"
namespace Common
{
class MemoryPool
{
private:
MemoryPool(const MemoryPool&);
MemoryPool& operator=(const MemoryPool&);
size_t _chunkSize;
Array<void*> _pages;
void* _next;
void* allocPage();
bool isPointerInPage(void* ptr, void* page);
public:
MemoryPool(size_t chunkSize);
~MemoryPool();
void* malloc();
void free(void* ptr);
void freeUnusedPages();
};
}
#endif