Introduced type matchers.

This commit is contained in:
Roberto Raggi
2009-11-23 11:56:44 +01:00
parent 51809d12a7
commit 0528f2407a
24 changed files with 540 additions and 51 deletions

View File

@@ -47,14 +47,11 @@
// THE SOFTWARE.
#include "MemoryPool.h"
#include <cstdlib>
#include <cstring>
#include <cassert>
using namespace CPlusPlus;
using namespace std;
MemoryPool::MemoryPool()
: _initializeAllocatedMemory(true),
_blocks(0),
@@ -68,12 +65,12 @@ MemoryPool::~MemoryPool()
{
if (_blockCount != -1) {
for (int i = 0; i < _blockCount + 1; ++i) {
free(_blocks[i]);
std::free(_blocks[i]);
}
}
if (_blocks)
free(_blocks);
std::free(_blocks);
}
bool MemoryPool::initializeAllocatedMemory() const
@@ -98,9 +95,9 @@ void *MemoryPool::allocate_helper(size_t size)
char *&block = _blocks[_blockCount];
if (_initializeAllocatedMemory)
block = (char *) calloc(1, BLOCK_SIZE);
block = (char *) std::calloc(1, BLOCK_SIZE);
else
block = (char *) malloc(BLOCK_SIZE);
block = (char *) std::malloc(BLOCK_SIZE);
ptr = block;
end = ptr + BLOCK_SIZE;
@@ -117,7 +114,7 @@ void MemoryPool::rewind(const State &state)
{
if (_blockCount == state.blockCount && state.ptr < ptr) {
if (_initializeAllocatedMemory)
memset(state.ptr, '\0', ptr - state.ptr);
std::memset(state.ptr, '\0', ptr - state.ptr);
ptr = state.ptr;
}