15MemoryPool::MemoryPool()
23MemoryPool::~MemoryPool()
26 for (
int i = 0; i < _allocatedBlocks; ++i) {
27 if (
char *b = _blocks[i])
35void MemoryPool::reset()
38 _ptr = _end =
nullptr;
41void *MemoryPool::allocate_helper(size_t size)
45 if (++_blockCount == _allocatedBlocks) {
46 if (! _allocatedBlocks)
47 _allocatedBlocks = DEFAULT_BLOCK_COUNT;
49 _allocatedBlocks *= 2;
51 _blocks = (
char **) realloc(_blocks,
sizeof(
char *) * _allocatedBlocks);
53 for (
int index = _blockCount; index < _allocatedBlocks; ++index)
54 _blocks[index] =
nullptr;
57 char *&block = _blocks[_blockCount];
60 block = (
char *) std::malloc(BLOCK_SIZE);
63 _end = _ptr + BLOCK_SIZE;
76void *Managed::operator
new(size_t size, MemoryPool *pool)
77{
return pool->allocate(size); }
79void Managed::operator
delete(
void *)
82void Managed::operator
delete(
void *, MemoryPool *)