Why does the STL reserve an interface for Allocator? Taking vectoras an example:
template<class T,class Allocator = std::allocator<T>>
class vector;
Since there are many options for allocating memory and constructing objects, for example,
operator new,delete,new[],delete[]which can do almost everything we need when we create an object.
So, why do STL containers, such as vector, need the Allocator interface, which in most cases is the default std::allocatorby default if we don't capsize it? Why not just use expressions new?
If the goal is to make user-defined distribution options possible, why not just let users provide their self-defined operator new,new[], etc.
source
share