std::allocator_traits<Alloc>::allocate
From cppreference.com
< cpp | memory | allocator traits
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Memory management library
(exposition only*)
(C++11)
(C++23)
(C++11)
(C++17)
(C++11)
(C++11)
(C++20)
(C++20)
(C++17)
(C++11)
(C++17)
(C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
Uninitialized storage (until C++20)
(until C++20*)
(until C++20*)
(until C++20*)
Garbage collector support (until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)
(C++11)
(C++17)
(C++20)
(C++17)
(C++11)
(C++11)
(C++11)
(until C++17*)
(C++11)
(C++17)
(C++26)
(C++26)
(C++11)
(C++11)
(C++11)
(C++23)
(C++23)
(C++11)
(C++20)
(C++11)
(C++11)
(C++20)
(C++26)
Defined in header
<memory>
static pointer allocate( Alloc& a, size_type n );
(1)
(since C++11) (constexpr since C++20)
static pointer allocate( Alloc& a, size_type n, const_void_pointer hint );
(2)
(since C++11) (constexpr since C++20)
Uses the allocator a to allocate n * sizeof(Alloc::value_type) bytes of uninitialized storage. An array of type Alloc::value_type[n] is created in the storage, but none of its elements are constructed.
1) Calls a.allocate(n).
2) Additionally passes memory locality hint hint. Calls a.allocate(n, hint) if possible. If not possible (e.g. a has no two-argument member function
allocate
), calls a.allocate(n).Contents
[edit] Parameters
a
-
allocator to use
n
-
the number of objects to allocate storage for
hint
-
pointer to a nearby memory location
[edit] Return value
The pointer returned by the call to a.allocate(n).
[edit] Notes
Alloc::allocate
was not required to create array object until P0593R6, which made using non-default allocator for std::vector and some other containers not well-defined according to a strict reading of the core language specification.
After calling allocate
and before construction of elements, pointer arithmetic of Alloc::value_type* is well-defined within the allocated array, but the behavior is undefined if elements are accessed.
[edit] Example
This section is incomplete
Reason: no example
Reason: no example