class template
<memory>

std::allocator

template <class T> class allocator;
Default allocator
Allocators are classes that define memory models to be used by some parts of the Standard Library, and most specifically, by STL containers.

This section describes the default allocator template allocator (lowercase). This is the allocator that all standard containers will use if their last (and optional) template parameter is not specified, and is the only predefined allocator in the standard library.

Other allocators may be defined. Any class having the same members as this default allocator and following its minimum requirements can be used as an allocator with the standard containers.
Other allocators may be defined. Any class Alloc for which allocator_traits<Alloc> produces a valid instantiation with the appropriate members defined can be used as an allocator on standard containers (Alloc may or may not implement the functionality through member functions).

Except for its destructor, no member of the standard default allocator class template shall introduce data races. Calls to member functions that allocate or deallocate storage shall occur in a single total order, and each such deallocation shall happen before the next allocation (if any) in this order.

Technically, a memory model described by allocators might be specialized for each type of object to be allocated and even may store local data for each container they work with. Although this does not happen with the default allocator.

Template parameters

T
Type of the elements allocated by the object (aliased as member type value_type).

Member types

memberdefinition in allocatorrepresents
value_typeTElement type
pointerT*Pointer to element
referenceT&Reference to element
const_pointerconst T*Pointer to constant element
const_referenceconst T&Reference to constant element
size_typesize_tQuantities of elements
difference_typeptrdiff_tDifference between two pointers
rebind<Type>member classIts member type other is the equivalent allocator type to allocate elements of type Type
memberdefinition in allocatorrepresents
value_typeTElement type
pointerT*Pointer to element
referenceT&Reference to element
const_pointerconst T*Pointer to constant element
const_referenceconst T&Reference to constant element
size_typesize_tQuantities of elements
difference_typeptrdiff_tDifference between two pointers
rebind<Type>member classIts member type other is the equivalent allocator type to allocate elements of type Type
propagate_on_container_move_assignmenttrue_typeIndicates that allocator shall propagate when the container is move-assigned

Member functions


Template specializations

Header <memory> provides a specialization of allocator for the void type, defined as:
1
2
3
4
5
6
7
template <> class allocator<void> {
public:
  typedef void* pointer;
  typedef const void* const_pointer;
  typedef void value_type;
  template <class U> struct rebind { typedef allocator<U> other; };
};