std::pmr::p...cate_object(3)

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

πŸ’– NAME πŸ’–

okay bestie, this is the C++ Standard Libary manual, section (3), and the function is std::pmr::polymorphic_allocator::allocate_object β€” the short description is literally the same thing: std::pmr::polymorphic_allocator::allocate_object. iconic, honestly πŸ’…


✨ Synopsis ✨

template< class U >                                     (since C++20)
[[nodiscard]] U* allocate_object( std::size_t n = 1 );

Allocates storage for n objects of type U using the underlying memory resource.

If std::numeric_limits<std::size_t>::max() / sizeof(U) < n, it throws std::bad_array_new_length; otherwise it’s equivalent to return static_cast<U*>(allocate_bytes(n * sizeof(U), alignof(U)));.


πŸŽ€ Parameters πŸŽ€

  • n β€” the number of objects to allocate storage for. That’s the whole parameter, bestie; she’s simple and she knows it 🫢

🌸 Return value 🌸

A pointer to the allocated storage. slay ✨


πŸ¦‹ Notes πŸ¦‹

This function was introduced for use with the fully-specialized allocator std::pmr::polymorphic_allocator<>, but it may be useful in any specialization as a shortcut to avoid having to rebind from std::pmr::polymorphic_allocator<T> to std::pmr::polymorphic_allocator<U>.

Since U is not deduced, it must be provided as a template argument when calling this function. no cap, you gotta say it with your chest πŸ’œ


😭 Exceptions 😭

Throws std::bad_array_new_length if n > std::numeric_limits<std::size_t>::max() / sizeof(U); may also be any exceptions thrown by the call to resource()->allocate.

bestie, read that condition carefully β€” this is the β€œtoo much math, too much size” situation, and she WILL throw πŸ’€

πŸ‘€ See also πŸ‘€

  • allocate_bytes β€” allocate raw aligned memory from the underlying resource (C++20) (public member function)
  • new_object β€” allocates and constructs an object (C++20) (public member function)
  • allocate β€” allocate memory (public member function)
  • allocate [static] β€” allocates uninitialized storage using the allocator (public static member function of std::allocator_traits<Alloc>)
  • allocate β€” allocates memory (public member function of std::pmr::memory_resource)

and that’s the whole page, bestie 🫢 source/version: http://cppreference.com Β· date: 2024.06.10 Β· footer tag: std::pmr::p...cate_object(3) β€” mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from