User:D41D8CD98F/Allocator
From cppreference.com
Template:cpp/concept/title Template:cpp/concept/navbar
Encapsulates a memory allocation and deallocation strategy.
Every standard library container that may need to allocate or release storage, including std::string, does so through an Allocator: an object of a class type that satisfies the following requirements.
Requirements
Given
-
A
, an Allocator type for typeT
-
a
, an object of typeA
-
B
, the corresponding Allocator type for typeU
(as obtained by rebindingA
) -
ptr
, a value of typeA::pointer
, obtained by calling A::allocate() -
cptr
, a value of typeA::const_pointer
, obtained by conversion fromptr
-
r
, a value of typeA::reference
, obtained by the expression*ptr
-
cr
, a value of typeA::const_reference
, obtained by the expression*cptr
or by conversion fromr
-
n
, a value of typeA::size_type
Expression | Requirements | Return type |
---|---|---|
A::pointer | Satisfies LegacyRandomAccessIterator. The implementation can always assume that this type is an alias of T*. | |
A::const_pointer | The implementation can always assume that this type is an alias of const T*. | |
A::reference | T& | |
A::const_reference | const T& | |
A::value_type | the type T
| |
A::size_type | A::size_type can represent the size of the largest object A can allocate. The implementation can always assume that this type is an alias of size_t.
|
unsigned integer type |
A::difference_type | A::difference_type can represent the difference of any two pointers to the objects allocated by A . The implementation can always assume that this type is an alias of ptrdiff_t.
|
signed integer type |
A::template rebind<U>::other | for any U , B::template rebind<T>::other is A
|
the type B
|
a.address(r) | A::pointer
| |
a.address(cr) | A::const_pointer
| |
a.allocate(n) | allocates storage suitable for n objects of type T , but does not construct them. May throw exceptions.
|
A::pointer
|
a.allocate(n, cp) | same as a.allocate(n) , but may use cp (a const_pointer obtained from a.allocate() or 0 ) in unspecified manner to aid locality
|
A::pointer
|
a.deallocate(ptr, n) | deallocates storage previously allocated by a call to a.allocate(n). Does not call destructors, if any objects were constructed, they must be destroyed before calling a.deallocate(). Does not throw exceptions. | (not used) |
a.max_size() | the largest value that can be passed to A::allocate()
|
A::size_type
|
a1 == a2 | returns true only if the storage allocated by the allocator a1 can be deallocated through a2 . Establishes reflexive, symmetric, and transitive relationship. The implementation can always assume that this returns true.
|
bool |
a1 != a2 | same as !(a1==a2) | bool |
A() | creates a default instance. Note: a destructor is assumed. | |
A a(b) | Given b as an instance of type B , constructs a such that B(a)==b and A(b)==a. Does not throw exceptions.
|
|
a.construct(ptr, t) | Effectively the same as ::new((void*)ptr) T(t)
|
(not used) |
a.destroy(ptr) | Effectively the same as ((T*)ptr)->˜T()
|
(not used) |