public member function
<memory>

std::allocator::allocate

pointer allocate (size_type n, allocator<void>::const_pointer hint=0);
Allocate block of storage
Attempts to allocate a block of storage with a size large enough to contain n elements of member typevalue_type(an alias of theallocator's template parameter), and returns a pointer to the first element.

The storage is aligned appropriately for objects of typevalue_type, but they are not constructed.

In the standard defaultallocator, the block of storage is allocated using::operator newone or more times, and throws bad_alloc if it cannot allocate the total amount of storage requested.

参数

n
Number of elements (each of sizesizeof(value_type)) to be allocated.
The member typesize_typeis an alias of size_t (in the standard default allocator) size_t is an unsigned integral type.
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. The address of an adjacent element is often a good choice.

返回值

A pointer to the initial element in the block of storage.

指针const_pointerare member types (defined as aliases ofT*const T*respectively instd::allocator<T>).

The standard default allocator throws bad_alloc if it cannot allocate the requested amount of storage.

另见