std::allocator::max_size(3)

๐Ÿ“ฆ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

๐ŸŒธ NAME ๐ŸŒธ

okay so bestie, welcome to the C++ Standard Library corner of the manual โ€” this is std::allocator::max_size(3), and she's here to tell you the absolute most n you could theoretically ask for. no cap, it's giving "how big can we go" energy. ๐Ÿ’…โœจ


๐Ÿ”ฅ Synopsis ๐Ÿ”ฅ

size_type max_size() const throw();   (until C++11)
                                      (since C++11)
size_type max_size() const noexcept;  (deprecated in C++17)
                                      (removed in C++20)

so what does she actually do? she returns the maximum theoretically possible value of n for which the call allocate(n, 0) could succeed. yes, allocate(n, 0) โ€” write it down, bestie. ๐Ÿ“

and in most implementations, this is literally just:

std::numeric_limits<size_type>::max() / sizeof(value_type)

slay, math queen. ๐Ÿงฎ๐Ÿ‘‘


๐Ÿฆ‹ Parameters ๐Ÿฆ‹

(none) โ€” zero, zilch, nada. she takes no parameters, she's lowkey low-maintenance like that. ๐Ÿ’–


๐ŸŽ€ Return value ๐ŸŽ€

the maximum supported allocation size. that's it, that's the tea. โ˜•โœจ


๐ŸŒˆ See also ๐ŸŒˆ

  • max_size returns the maximum object size supported by the allocator [static] โ€” as in, a public static member function of std::allocator_traits<Alloc>. iykyk. ๐Ÿซถ

shoutout to the source http://cppreference.com and the 2024.06.10 date โ€” that's the version vibe, periodt. ๐Ÿ’…๐ŸŒธ

๐Ÿ“ฆ where this page comes from