std::pmr::p...or::allocate(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– 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 πŸ”₯

Throws std::bad_array_new_length if n > std::numeric_limits<std::size_t>::max() / sizeof(T); may also throw any exceptions thrown by the call to resource()->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: allocate might allocate storage of wrong size; correct behavior: throws length_error instead.
  • LWG 3237 β€” DR; applied to: C++17; behavior as published: the exception thrown by allocate was inconsistent with std::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 of std::allocator_traits<Alloc>)
  • allocate β€” allocates memory (public member function of std::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