Created
June 23, 2015 05:46
-
-
Save cocodrips/beffcd9156ba8ff37287 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#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