Last active
July 5, 2020 12:55
-
-
Save naveenspace7/8030d88916e278972672c4723713935c to your computer and use it in GitHub Desktop.
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
#include <vector> | |
void * mem_pool_ptr; | |
template<typename type> | |
struct MyAlloc : allocator<type> | |
{ | |
type* allocate(size_t size) | |
{ | |
cout << "Allocate function called with size " << size << endl; | |
return new(mem_pool_ptr) type[size]; | |
} | |
template <typename U> struct rebind | |
{ | |
typedef MyAlloc<U> other; | |
}; | |
}; | |
int main() | |
{ | |
vector<int, MyAlloc<int>> v1(7,7); | |
// ... | |
v1.push_back(3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment