Namespaces
Variants
Actions

std::allocator

From cppreference.com
< cpp‎ | memory
 
 
Memory management library
(exposition only*)
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
(until C++20*)
(until C++20*)

Garbage collector support (until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
 
 
Defined in header <memory>
template< class T >
struct allocator;
(1)
template<>
struct allocator<void>;
(2) (deprecated in C++17)
(removed in C++20)

The std::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.

The explicit specialization for void lacks the member typedefs reference, const_reference, size_type and difference_type. This specialization declares no member functions.

(until C++20)

The default allocator satisfies allocator completeness requirements.

(since C++17)

Contents

[edit] Member types

Type Definition
value_type T
pointer (deprecated in C++17)(removed in C++20) T*
const_pointer (deprecated in C++17)(removed in C++20) const T*
reference (deprecated in C++17)(removed in C++20) T&
const_reference (deprecated in C++17)(removed in C++20) const T&
size_type std::size_t
difference_type std::ptrdiff_t
propagate_on_container_move_assignment (C++11) std::true_type
rebind (deprecated in C++17)(removed in C++20) template< class U >

struct rebind
{
    typedef allocator<U> other;
};

is_always_equal (C++11)(deprecated in C++23)(removed in C++26) std::true_type

[edit] Member functions

creates a new allocator instance
(public member function) [edit]
destructs an allocator instance
(public member function) [edit]
(until C++20)
obtains the address of an object, even if operator& is overloaded
(public member function) [edit]
allocates uninitialized storage
(public member function) [edit]
allocates uninitialized storage at least as large as requested size
(public member function) [edit]
deallocates storage
(public member function) [edit]
(until C++20)
returns the largest supported allocation size
(public member function) [edit]
(until C++20)
constructs an object in allocated storage
(public member function) [edit]
(until C++20)
destructs an object in allocated storage
(public member function) [edit]

[edit] Non-member functions

(removed in C++20)
compares two allocator instances
(public member function) [edit]

[edit] Notes

The member template class rebind provides a way to obtain an allocator for a different type. For example,