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

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

πŸ’– NAME πŸ’–

This is the std::pmr::p...locate_bytes(3) page from the C++ Standard Libary manual β€” yes, that's the header spelling, we're keeping the detail and moving on πŸ’…. The name is std::pmr::polymorphic_allocator::allocate_bytes β€” std::pmr::polymorphic_allocator::allocate_bytes. Yep, the original repeats it, and we're not skipping a single crumb. Periodt.

✨ Synopsis ✨

Okay so this one is tagged (since C++20), bestie. Here's the signature β€” the version tag is literally just a tag, not an argument:

[[nodiscard]] void* allocate_bytes( std::size_t nbytes,
                                    std::size_t alignment =
                                    alignof(std::max_align_t) );

Allocates nbytes bytes of storage at specified alignment alignment using the underlying memory resource. It is equivalent to literally doing:

return resource()->allocate(nbytes, alignment);

πŸŽ€ Parameters πŸŽ€

  • nbytes β€” the number of bytes to allocate.
  • alignment β€” the alignment to use.

🫢 Return value 🫢

A pointer to the allocated storage. That's the whole return value, no cap πŸ’–.

πŸ’­ Notes πŸ’­

This function was introduced for use with the fully-specialized allocator std::pmr::polymorphic_allocator<>, but it may be useful in any specialization. So yes, it can pop off outside the fully-specialized case too.

The return type is void* (rather than, e.g., std::byte*) to support conversion to an arbitrary pointer type U* by static_cast<U*>. That's the reason, bestie, and it's lowkey iconic.

😭 Exceptions 😭

May throw any exceptions thrown by the call to resource()->allocate. So if the underlying resource is being dramatic, this function is matching energy 😭.

πŸ‘€ See also πŸ‘€

  • 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 β€” allocate memory (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)

Source: http://cppreference.com Β· version/date: 2024.06.10 Β· manual: std::pmr::p...locate_bytes(3). Bye bestie, go allocate something iconic πŸ’–βœ¨

πŸ“¦ where this page comes from