Allocator interface. More...
|Default constructor. |
|virtual void *||allocate (std::size_t size)|
|Allocates size bytes of memory. |
|virtual void||deallocate (void *p, std::size_t)|
|Deallocates memory of size bytes. |
Allocators allow a program to use different methods of allocating and deallocating raw memory. The default implementation will simply use new and delete. Custom allocators are implemented by overriding the two methods allocate() and deallocate() of the Pt::Allocator base class. The following example tracks the amount of allocated memory:
This interface differs from std::allocator used for STL containers, because it allows to allocate memory of different sizes through the same interface. The std::allocator is meant to allocate and also construct objects of the same size. It is however possible, to implement a std::allocator using the raw memory allocators described here.