std::pmr::p...or::allocate(3)
π NAME π
std::pmr::polymorphic_allocator::allocate β std::pmr::polymorphic_allocator::allocate (yes, the name is literally the name twice, and that's iconic π
)
okay so this is the std::pmr::polymorphic_allocator::allocate page from the C++ Standard Libary manual. The header is out here saying <blue>C++ Standard Libary</blue>, and the title is squished to std::pmr::p...or::allocate(3) π. bestie, let's get into it.
β¨ Synopsis β¨
T* allocate( std::size_t n ); (since C++17)
(until C++20)
[[nodiscard]] T* allocate( std::size_t n ); (since C++20)
This one allocates storage for n objects of type T using the underlying memory resource. No cap, that's the whole job. π
Equivalent to this, literally:
return static_cast<T*>(resource()->allocate(n *
sizeof(T),
alignof(T)));.
πΈ Parameters πΈ
nβ the number of objects to allocate storage for. That's the whole parameter list, periodt. β¨
π Return value π
A pointer to the allocated storage. That's it. That's the return. π
π₯ Exceptions π₯
Throwsstd::bad_array_new_lengthifn > std::numeric_limits<std::size_t>::max() / sizeof(T); may also throw any exceptions thrown by the call toresource()->allocate. π
π©Ή Defect reports π©Ή
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. Obsessed with retroactive fixes, honestly. π«Ά
LWG 3038β DR; applied to:C++17; behavior as published:allocatemight allocate storage of wrong size; correct behavior: throwslength_errorinstead.LWG 3237β DR; applied to:C++17; behavior as published: the exception thrown byallocatewas inconsistent withstd::allocator::allocate; correct behavior: made consistent.
π¦ See also π¦
allocate_bytesβ allocate raw aligned memory from the underlying resource (C++20) (public member function)allocate_objectβ allocates raw memory suitable for an object or an array (C++20) (public member function)new_objectβ allocates and constructs an object (C++20) (public member function)allocateβ allocates uninitialized storage using the allocator[static](public static member function ofstd::allocator_traits<Alloc>)allocateβ allocates memory (public member function ofstd::pmr::memory_resource)
okay that's the whole page, bestie π
β source: http://cppreference.com, version/date: 2024.06.10, and the footer title is std::pmr::p...or::allocate(3). mwah π«Ά
π¦ 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