diff options
author | David Robillard <d@drobilla.net> | 2009-07-03 06:52:51 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-07-03 06:52:51 +0000 |
commit | 71cb844f7d7cc6406c66a580fdb37f8c6e36d171 (patch) | |
tree | 679a724866ba9ad9fddd28a57c6c9638fb2af1a3 /src/gc.cpp | |
parent | 58b9333e2d889abd26ef16eda496c0a47209ab58 (diff) | |
download | resp-71cb844f7d7cc6406c66a580fdb37f8c6e36d171.tar.gz resp-71cb844f7d7cc6406c66a580fdb37f8c6e36d171.tar.bz2 resp-71cb844f7d7cc6406c66a580fdb37f8c6e36d171.zip |
Include and use TLSF fast realtime allocator.
git-svn-id: http://svn.drobilla.net/resp/tuplr@171 ad02d1e2-f140-0410-9f75-f8b11f17cedd
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; |