Custom allocator is good
Code:
#include <vector>
#include <iostream>
template<class T>
class talloc: public std::allocator<T>
{
public:
pointer allocate( size_type _Count, const void* _Hint)
{
//return new(_Count* sizeof(T));
return std::allocator<T>::allocate( size_type _Count, const void* _Hint);
}
void deallocate(pointer _Ptr, size_type _Count)
{
//for(pointer p =0; p <_Count; ++p)
// delete (_Ptr+p);
std::allocator<T>::deallocate(pointer _Ptr, size_type _Count);
}
};
int main()
{
std::vector<int, talloc<int>> tv(10);
tv.push_back(23);
std::cout << tv.back();
return 0;
}