Namespaces
Variants
Views
Actions

std::allocator

From cppreference.com
Defined in header <memory>
template< class T >
struct allocator;
(1)
template<>
struct allocator<void>;
(2)

1) The std::allocator class template is the default allocator used by all standard library containers if no user-specified allocator is provided. Custom allocators are required to implement the public interface of std::allocator or to provide a specialization of std::allocator_traits.

2) Specialization for void is provided, which lacks the member typedefs reference and const_reference because there are no references to void and size_type and difference_type because there are no arrays of void. This specialization declares no member functions.

Contents

[edit] Notes

The default allocator and all custom allocators are required to be stateless: all instances of a given allocator type have to be interchangeable, compare equal, and deallocate memory allocated by any other instance of the same allocator type. (until C++11)

The default allocator is stateless, all instances compare equal and are able to deallocate memory allocated by any other instance, but custom allocators may hold state. Each container or another allocator-aware object stores an instance of the supplied allocator and controls allocator replacement through std::allocator_traits. (since C++11)

[edit] Member types

Type Definition
value_type T
pointer T*
const_pointer const T*
reference T&
const_reference const T&
size_type std::size_t
difference_type std::ptrdiff_t
rebind template< class U > struct rebind { typedef allocator<U> other; };

[edit] Member functions

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

[edit] Non-member functions

compares two allocator instances
(public member function) [edit]

[edit] See also

provides information about allocator types
(class template) [edit]
implements multi-level allocator for multi-level containers
(class template) [edit]
checks if the specified type supports uses-allocator construction
(class template) [edit]