public static member function
<memory>
static pointer allocate (allocator_type& alloc, size_type n);static pointer allocate (allocator_type& alloc, size_type n, const_void_pointer hint);
Allocate block of storage
Uses allocator alloc to attempt the allocation of a block of storage with a size large enough to contain n elements properly aligned, and returns a pointer to the first element.
No element objects are constructed by the call (see allocator_traits::construct).
In the non-specialized definition of allocator_traits, this member function simply callsalloc.allocate(n)(或alloc.allocate(n,hint)) to achieve this functionality, but a specialization for a specific allocator type may provide a different definition.
参数
- alloc
- Allocator object
allocator_typeis an alias of allocator_traits's template parameter.
- n
- Number of elements to be allocated.
size_typeis a member type of allocator_traits.
- hint
- Either0or a value previously obtained by another call toallocateand not yet freed with deallocate.
When it is not0, this value may be used as a hint to improve performance by allocating the new block near the one specified.
const_void_pointeris a member type of allocator_traits.
返回值
A pointer to the location of the first element in the block of storage.
指针is a member type of allocator_traits.
另见
- allocator_traits::deallocate
- Release block of storage (public static member function)
- allocator_traits::construct
- Construct an element (public static member function)
- allocator::allocate
- Allocate block of storage (public member function)