#include <cstdint>
#include <stack>
template<typename Tp>
class FixedAllocator {
private:
PageAllocator *page_allocator_;
std::stack<Tp*> free_pull;
public:
explicit FixedAllocator(std::uint64_t page_size) {
page_allocator_ = new PageAllocator(page_size*sizeof(Tp));
}
Tp* Allocate() {
if (!free_pull.empty()) {
Tp* answer = free_pull.top();
free_pull.pop();
return answer;
} else {
return reinterpret_cast<Tp*>(page_allocator_->Allocate());
}
}
void Deallocate(Tp* p) {
free_pull.push(p);
}
[[nodiscard]] const PageAllocator& InnerAllocator() const noexcept {
return *page_allocator_;
}
};