BumpAllocatorSTL
BumpAllocator for STL containers.
14 lines tested
Usage: vector<vector<int, small<int>>> ed(N);
content/various/BumpAllocatorSTL.h — Simon Lindholm, source: me
char buf[450 << 20] alignas(16);
size_t buf_ind = sizeof buf;
template<class T> struct small {
typedef T value_type;
small() {}
template<class U> small(const U&) {}
T* allocate(size_t n) {
buf_ind -= n * sizeof(T);
buf_ind &= 0 - alignof(T);
return (T*)(buf + buf_ind);
}
void deallocate(T*, size_t) {}
};