imsuck's library

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub imsuck/library

:warning: other/bump_alloc.hpp

Code

#pragma once

char BUF[256 << 20]; // 256 MB
size_t BUFP = sizeof(BUF);
void *operator new(size_t s) { return &BUF[BUFP -= s]; }
void operator delete(void *) noexcept {}
void operator delete(void *, size_t) noexcept {}
template<class T> struct bump {
    using value_type = T;
    bump() {}
    template<class U> bump(U, ...) {}
    template<class U> struct rebind {
        using other = bump<U>;
    };
    T *allocate(size_t n) {
        BUFP -= n * sizeof(T);
        BUFP &= 0 - alignof(T);
        return (T *)(BUF + BUFP);
    }
    void deallocate(T *, size_t) {}
};
#line 2 "other/bump_alloc.hpp"

char BUF[256 << 20]; // 256 MB
size_t BUFP = sizeof(BUF);
void *operator new(size_t s) { return &BUF[BUFP -= s]; }
void operator delete(void *) noexcept {}
void operator delete(void *, size_t) noexcept {}
template<class T> struct bump {
    using value_type = T;
    bump() {}
    template<class U> bump(U, ...) {}
    template<class U> struct rebind {
        using other = bump<U>;
    };
    T *allocate(size_t n) {
        BUFP -= n * sizeof(T);
        BUFP &= 0 - alignof(T);
        return (T *)(BUF + BUFP);
    }
    void deallocate(T *, size_t) {}
};
Back to top page