diff options
Diffstat (limited to 'src/gc.cpp')
-rw-r--r-- | src/gc.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -23,15 +23,26 @@ #include <set> #include <iostream> #include "tuplr.hpp" +#include "tlsf.h" using namespace std; +GC::GC(size_t pool_size) +{ + _pool = tlsf_init(malloc(pool_size), pool_size); +} + +GC::~GC() +{ + tlsf_destroy((tlsf_t*)_pool); +} + void* GC::alloc(size_t size, GC::Tag tag) { size += (4 - (size % 4)); // Align to 32-bits size += sizeof(Object::Header); - void* ret = malloc(size); + void* ret = tlsf_malloc((tlsf_t*)_pool, size); ((Object::Header*)ret)->mark = 0; ((Object::Header*)ret)->tag = tag; ret = (char*)ret + sizeof(Object::Header); @@ -76,14 +87,14 @@ GC::collect(const Roots& roots) } else { switch ((*i)->tag()) { case GC::TAG_FRAME: - free((char*)(*i) - sizeof(Object::Header)); + tlsf_free((tlsf_t*)_pool, (char*)(*i) - sizeof(Object::Header)); _heap.erase(i); break; case GC::TAG_AST: AST* ast = (AST*)*i; if (!ast->to<AType*>()) { // FIXME (ast)->~AST(); - free((char*)(*i) - sizeof(Object::Header)); + tlsf_free((tlsf_t*)_pool, ((char*)(*i) - sizeof(Object::Header))); _heap.erase(i); } break; |