|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
The template class describes an object that manages storage allocation and freeing for arrays of objects of type Type. An object of class allocator is the default allocator object specified in the constructors for several container template classes in the Standard C++ Library.
For a list of all members of this type, see.
The type of object for which storage is being allocated or deallocated.
All the Standard Template Library containers have a template parameter that defaults to allocator. Template class allocator supplies several type definitions that are rather pedestrian. They hardly seem worth defining. But another class with the same members might choose more interesting alternatives. Constructing a container with an allocator object of such a class gives individual control over allocation and freeing of elements controlled by that container.
For example, an allocator object might allocate storage on a private heap. It might allocate storage on a far heap, requiring nonstandard pointers to access the allocated objects. It might also specify, through the type definitions it supplies, that elements be accessed through special accessor objects that manage shared memory, or perform automatic garbage collection. Hence, a class that allocates storage using an allocator object should use these types for declaring pointer and reference objects, as the containers in the Standard C++ Library do.
When you derive from allocator class, you have to provide a rebind struct, whose _Other typedef references your newly-derived class.
Thus, an allocator defines the following types:
pointer behaves like a pointer to Type.
const_pointer behaves like a const pointer to Type.
reference behaves like a reference to Type.
const_reference behaves like a const reference to Type.
These Types specify the form that pointers and references must take for allocated elements. (allocator::pointer is not necessarily the same as Type* for all allocator objects, even though it has this obvious definition for class allocator.)