Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created June 23, 2015 05:46
Show Gist options
  • Save cocodrips/beffcd9156ba8ff37287 to your computer and use it in GitHub Desktop.
Save cocodrips/beffcd9156ba8ff37287 to your computer and use it in GitHub Desktop.
#include <vector>
#include <memory>
#include <cstdlib>
#include <iostream>
template<class T>
class MyAllocator : public std::allocator<T> {
public:
MyAllocator() {}
MyAllocator(const MyAllocator& x) {}
template<class U>
MyAllocator(const MyAllocator<U>& x) {}
pointer allocate(size_type n) {
std::cout << "allocate " << n * sizeof(T) << "bytes" << std::endl;
return (pointer) std::malloc(n * sizeof(T));
}
void deallocate(pointer ptr, size_type n) {
std::free(ptr);
}
template<class U>
struct rebind {typedef MyAllocator<U> other;};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment