A Tcl like command language made for the Clinl kernel testing
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
567 B

#pragma once
#include "arena.hpp"
#include <array>
class memory_pool{
std::array<arena,256> _pool;
public:
memory_pool()
: _pool()
{
_pool.fill(arena());
for(auto& a : _pool)
a = arena(4096);
}
memory_pool(memory_pool&) = delete;
memory_pool(memory_pool&&) = delete;
void* allocate(size_t sz)
{
for(auto& a : _pool)
{
void* ptr = a.allocate(sz);
if(ptr!=nullptr)
return ptr;
}
return nullptr;
}
void desallocate(void* ptr)
{
for(auto& a : _pool)
{
bool success = a.desallocate(ptr);
if(success)
return;
}
}
};