|
|
- #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;
- }
- }
- };
|