std::allocator
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) | |
destructs an allocator instance (public member function) | |
obtains the address of an object, even if operator& is overloaded (public member function) | |
allocates uninitialized storage (public member function) | |
deallocates storage (public member function) | |
returns the largest supported allocation size (public member function) | |
constructs an object in allocated storage (public member function) | |
destructs an object in allocated storage (public member function) |
[edit] Non-member functions
compares two allocator instances (public member function) |
[edit] See also
(C++11) |
provides information about allocator types (class template) |
(C++11) |
implements multi-level allocator for multi-level containers (class template) |
(C++11) |
checks if the specified type supports uses-allocator construction (class template) |