Skip to content

Instantly share code, notes, and snippets.

@naveenspace7
Last active July 5, 2020 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naveenspace7/8030d88916e278972672c4723713935c to your computer and use it in GitHub Desktop.
Save naveenspace7/8030d88916e278972672c4723713935c to your computer and use it in GitHub Desktop.
#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