The default std::allocator
class is stateless in C++. This means any instance of an std::allocator
can deallocate memory allocated by another std::allocator
instance. What is then the point of having instances of allocators to allocate memory?
For instance, why is memory allocated like this:
allocator<T> alloc, alloc2;
T* buffer = alloc.allocate(42);
alloc2.deallocate(buffer);
When functions could easily do that same job:
T* buffer = allocate(42);
deallocate(buffer);