#pragma once #include #include template class FixedAllocator { PageAllocator page_allocator_; public: explicit FixedAllocator(std::uint64_t page_size) : page_allocator_(page_size) { pg_size = page_size; } Tp* Allocate() { for (uint64_t i = 0; i < dim.size(); i++) { if (dim[i].second < pg_size) { dim[i].second++; return dim[i].first; } } dim.emplace_back(static_cast(page_allocator_.Allocate()), 1); return dim.back().first; } void Deallocate(Tp* p) { auto ind = getindex(p); if (ind != -1) { dim[ind].second--; } } const PageAllocator& InnerAllocator() const noexcept { return page_allocator_; } private: std::vector> dim; uint64_t pg_size; int64_t getindex(Tp* p) { for (uint64_t i = 0; i < dim.size(); i++) if (dim[i].first == p) return i; return -1; } };