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.

38 lines
567 B

5 years ago
  1. #pragma once
  2. #include "arena.hpp"
  3. #include <array>
  4. class memory_pool{
  5. std::array<arena,256> _pool;
  6. public:
  7. memory_pool()
  8. : _pool()
  9. {
  10. _pool.fill(arena());
  11. for(auto& a : _pool)
  12. a = arena(4096);
  13. }
  14. memory_pool(memory_pool&) = delete;
  15. memory_pool(memory_pool&&) = delete;
  16. void* allocate(size_t sz)
  17. {
  18. for(auto& a : _pool)
  19. {
  20. void* ptr = a.allocate(sz);
  21. if(ptr!=nullptr)
  22. return ptr;
  23. }
  24. return nullptr;
  25. }
  26. void desallocate(void* ptr)
  27. {
  28. for(auto& a : _pool)
  29. {
  30. bool success = a.desallocate(ptr);
  31. if(success)
  32. return;
  33. }
  34. }
  35. };