std::alloca...ts::allocate(3)
π std::alloca...ts::allocate(3) π
okay bestie, welcome to the C++ Standard Libary manual page for std::allocator_traits::allocate β yes, the manual spells it βLibary,β and we are not fixing it, periodt π
πΈ NAME πΈ
std::allocator_traits::allocate β std::allocator_traits::allocate
It literally says the same thing twice. Iconic recursive main character energy, no cap π«Ά
β¨ Synopsis β¨
π¦ Defined in header <memory> π¦
(1) (since C++11) (until C++20)
static pointer allocate( Alloc& a, size_type n );
(1) (since C++20)
[[nodiscard]] static constexpr pointer allocate( Alloc& a, size_type n );
(2) (since C++11) (until C++20)
static pointer allocate( Alloc& a, size_type n,
const_void_pointer hint );
(2) (since C++20)
[[nodiscard]] static constexpr pointer allocate(
Alloc& a, size_type n,
const_void_pointer hint );
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. π§β¨
- Calls
a.allocate(n). - Additionally passes memory locality hint
hint. Callsa.allocate(n, hint)if possible. If not possible (e.g.ahas no two-argument member functionallocate), callsa.allocate(n).
π Parameters π
aβ allocator to use π«Άnβ the number of objects to allocate storage for π«hintβ pointer to a nearby memory location π
π Return value π
The pointer returned by the call to a.allocate(n). That's the whole vibe check, bestie β pointer goes out, pointer comes back π₯
π¦ 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. π
bestie, that last bit is a real warning: pointer arithmetic inside the allocated array is fine before elements are constructed, but accessing elements is undefined behavior. no cap, do not touchy. π
π Example π
This section is incomplete
Reason: no example
literally βno exampleβ π it's giving unfinished homework energy, but that's what the page says, so we keep it. π
π See also π
allocateallocates uninitialized storage (public member function ofstd::allocator<T>) β¨
ποΈ Category ποΈ
- Todo no example
kisses, bestie π this page is from the C++ Standard Libary manual; source: http://cppreference.com, version/date: 2024.06.10. slay and stay safe out there with your uninitialized storage ππ¦π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms