#pragma once
 
template<typename Tp>
class FixedAllocator {
    PageAllocator page_allocator_;
 
public:
    FixedAllocator(std::uint64_t page_size) : page_allocator_(PageAllocator(page_size)),
    page_size(page_size) {};
 
    Tp *Allocate() {
        if (this->pages.empty()) {
            Tp *tmp1 = static_cast<Tp *>(this->page_allocator_.Allocate());
            for (uint64_t i = 0; i < this->page_size; ++i) {
                this->pages.push_back(++tmp1);
            }
        }
        Tp *tmp2 = this->pages.back();
        this->pages.pop_back();
        return tmp2;
    };
 
    void Deallocate(Tp *p) {
        this->pages.push_back(p);
    };
 
    const PageAllocator &InnerAllocator() const noexcept {
        return this->page_allocator_;
    };
private:
    std::uint64_t page_size{};
    std::vector<Tp *> pages{};
};