C++ Standard Library C++ STL Library

C++ <memory> - allocator class template



The C++ <memory> allocator class template is the default Allocator used by all standard library containers if no user-specified allocator is provided. The default allocator is stateless, that is, all instances of the given allocator are interchangeable, compare equal and can deallocate memory allocated by any other instance of the same allocator type.

Syntax

template <class T> class allocator;

Parameters

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

Member Types

Member typesDefinitionDescription
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
Member typesDefinitionDescription
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

FunctionsDescription
(constructor) Construct allocator object
(destructor) Allocator destructor
address Return address
allocate Allocate block of storage
deallocate Release block of storage
max_size Maximum size possible to allocate
construct Construct an object
destroy Destroy an object.

Template specializations

The header <memory> provides a specialization of allocator for the void type which is defined as:

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; };
};

❮ C++ <memory> Library