Skip to content

Instantly share code, notes, and snippets.

@komiga
Created August 3, 2012 05:13
Show Gist options
  • Save komiga/3244597 to your computer and use it in GitHub Desktop.
Save komiga/3244597 to your computer and use it in GitHub Desktop.
Allocator class
class Allocator {
public:
virtual std::size_t get_num_allocations() const=0;
virtual std::size_t get_allocation_size(void* p) const=0;
virtual void* allocate(std::size_t size, std::size_t align=0)=0;
virtual void deallocate(void* p)=0;
template<class U, typename ...Args>
inline U* construct(Args&&... args) {
return new (allocate(sizeof(U), alignof(U))) U(std::forward<Args>(args)...);
}
template<class U>
inline void destruct(U* p) {
if (p) {
p->~U();
deallocate(p);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment