Skip to content

Commit

Permalink
added missing arena
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugobros3 committed Jan 9, 2025
1 parent d79895d commit ad24820
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/arena.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "artic/arena.h"

#include <cstdlib>

Arena::Arena() : _block_size(4096) {
_data = { malloc(_block_size) };
_available = _block_size;
}

Arena::~Arena() {
for (auto& ptr : _data)
free(ptr);
}

void Arena::grow() {
_block_size *= 2;
_data.push_back( malloc(_block_size) );
_available = _block_size;
}

void* Arena::alloc(size_t size) {
while (size > _available)
grow();
size_t ptr = reinterpret_cast<size_t>(_data.back()) + _block_size - _available;
_available -= size;
return reinterpret_cast<void*>(ptr);
}

0 comments on commit ad24820

Please sign in to comment.