Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- template<typename Tp>
- class FixedAllocator {
- PageAllocator page_allocator_;
- std::uint64_t fuck_obama = 0;
- std::vector<Tp *> fuck_klevch;
- public:
- explicit FixedAllocator(std::uint64_t page_size) :
- page_allocator_(page_size * sizeof(Tp)) {
- fuck_obama = page_size;
- }
- Tp* Allocate() {
- if (fuck_klevch.empty()) {
- Tp * start;
- start = static_cast<Tp *>(page_allocator_.Allocate());
- fuck_klevch.push_back(start);
- for (auto i = 0; i < fuck_obama - 1; ++i) {
- start++;
- fuck_klevch.push_back(start);
- }
- }
- auto obama = fuck_klevch[fuck_klevch.size() - 1];
- fuck_klevch.resize(fuck_klevch.size() - 1);
- return obama;
- }
- void Deallocate(Tp* p) {
- fuck_klevch.push_back(p);
- }
- const PageAllocator& InnerAllocator() const noexcept {
- return page_allocator_;
- }
- };
Add Comment
Please, Sign In to add comment