Created
August 3, 2012 05:13
-
-
Save komiga/3244597 to your computer and use it in GitHub Desktop.
Allocator class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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