13MemoryPool::MemoryPool()
21MemoryPool::~MemoryPool()
24 for (
int i = 0; i < _allocatedBlocks; ++i) {
25 if (
char *b = _blocks[i])
33void MemoryPool::reset()
36 _ptr = _end =
nullptr;
39void *MemoryPool::allocate_helper(size_t size)
43 if (++_blockCount == _allocatedBlocks) {
44 if (! _allocatedBlocks)
45 _allocatedBlocks = DEFAULT_BLOCK_COUNT;
47 _allocatedBlocks *= 2;
49 _blocks = (
char **) realloc(_blocks,
sizeof(
char *) * _allocatedBlocks);
51 for (
int index = _blockCount; index < _allocatedBlocks; ++index)
52 _blocks[index] =
nullptr;
55 char *&block = _blocks[_blockCount];
58 block = (
char *) std::malloc(BLOCK_SIZE);
61 _end = _ptr + BLOCK_SIZE;
74void *Managed::operator
new(size_t size, MemoryPool *pool)
75{
return pool->allocate(size); }
77void Managed::operator
delete(
void *)
80void Managed::operator
delete(
void *, MemoryPool *)