std::pmr::u...:do_allocate(3)

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

πŸŽ€ std::pmr::unsynchronized_pool_resource::do_allocate πŸŽ€

okay so this is a page straight out of the C++ Standard Library manual, and it's all about one very specific little overridden function. bestie, it's giving "niche but iconic" and we're gonna get into it πŸ’…


✨ NAME ✨

std::pmr::unsynchronized_pool_resource::do_allocate β€” yes it's the same name twice, that's just how manpages do, don't @ me πŸ’€


🌸 Synopsis 🌸

virtual void* do_allocate( std::size_t bytes, std::size_t alignment );

(since C++17) ⭐

It allocates storage, that's the whole vibe. But there's lore:

  • If the pool that got selected for a block of size bytes can't satisfy the request from its own internal data structures, it calls allocate() on the upstream memory resource to go get some memory. like "hey bestie upstream, can you spot me" 🫢
  • And if the size you requested is bigger than what the largest pool can even handle? Then memory gets allocated by calling allocate() on the upstream memory resource too. no pool for you, straight to upstream, periodt πŸ’…

πŸ¦‹ Return value πŸ¦‹

A pointer to allocated storage that's at least bytes bytes in size β€” and it's aligned to the specified alignment if such alignment is supported 🌈 β€” and aligned to alignof(std::max_align_t) otherwise. either way you're getting a pointer, and it's not messing around.


πŸ”₯ Exceptions πŸ”₯

Throws nothing unless calling allocate() on the upstream memory resource throws. that's it, that's the whole rule. very "i'm chill until the upstream is not chill" energy 😭


πŸ’– See also πŸ’–

  • allocate β€” allocates memory ✨ (public member function of std::pmr::memory_resource)
  • do_allocate β€” allocates memory ✨ [virtual] (virtual private member function of std::pmr::memory_resource)

(iykyk, they're all just allocate girlies in different outfits πŸ‘‘)


🌈 a lil sign-off 🌈

this page came to you courtesy of http://cppreference.com, dated 2024.06.10 β€” so if anything's changed since then, that's a conversation for future you. mwah, go allocate something responsibly πŸ“πŸ§šπŸ’œ

πŸ“¦ where this page comes from