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 types | Definition | Description |
value_type | T | Element type |
pointer | T* | Pointer to element |
reference | T& | Reference to element |
const_pointer | const T* | Pointer to constant element |
const_reference | const T& | Reference to constant element |
size_type | size_t | Quantities of elements |
difference_type | ptrdiff_t | Difference between two pointers |
rebind<Type> | member class | Its member type other is the equivalent allocator type to allocate elements of type Type |
Member types | Definition | Description |
value_type | T | Element type |
pointer | T* | Pointer to element |
reference | T& | Reference to element |
const_pointer | const T* | Pointer to constant element |
const_reference | const T& | Reference to constant element |
size_type | size_t | Quantities of elements |
difference_type | ptrdiff_t | Difference between two pointers |
rebind<Type> | member class | Its member type other is the equivalent allocator type to allocate elements of type Type |
propagate_on_container_move_assignment | true_type | Indicates that allocator shall propagate when the container is move-assigned |
Member Functions
Functions | Description |
(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