Create your own allocator Posted on 2018-06-26 The example is showing below. 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748#include <iostream>#include <memory>#include <vector>template <class T>class TrackingAllocator{ public: using value_type = T; using pointer = T *; using const_pointer = const T *; using void_pointer = void *; using const_void_pointer = const void*; using size_type = size_t; using difference_type = std::ptrdiff_t; TrackingAllocator() = default; ~TrackingAllocator() = default; size_type get_allocations() { return mAllocations; } pointer allocate(size_type num_objects) { return static_cast<pointer>(operator new(sizeof(value_type)*num_objects)); } void deallocate(pointer p, size_type num_objects) { operator delete(p); } size_type max_size() const{ return std::numeric_limits<size_type>::max(); }private: static size_type mAllocations;};template <class T>typename TrackingAllocator<T>::size_type TrackingAllocator<T>::mAllocations = 0;int main () { std::vector<int, TrackingAllocator<int> > v(5); return 0;}