#include <vector>

template<typename Tp>
class FixedAllocator {
    PageAllocator* page_allocator_;
    std::uint64_t size;
    std::vector <Tp*> cells;

public:
    explicit FixedAllocator(std::uint64_t page_size) {
        size = page_size;
        page_allocator_ = new PageAllocator(sizeof(Tp) *size);
    }
    Tp* Allocate() {
        if (cells.size() != 0) {
            Tp* cell = cells[0];
            cells.pop_back();
            return cell;
        } else {
            Tp *allocation;
            allocation = (Tp*)(page_allocator_->Allocate());
            for (size_t i = 0; i < this->size; i++) {
                cells.push_back(&allocation[i]);
            }
            Tp* cell = cells[0];
            cells.pop_back();
            return cell;
        }
    }
    void Deallocate(Tp* p) {
        cells.push_back(p);
    }
    const PageAllocator& InnerAllocator() const noexcept {
        return *page_allocator_;
    }
};