Namespaces
Variants

std::allocator_traits<Alloc>:: max_size

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
Definiert in Header <memory>
static size_type max_size ( const Alloc & a ) noexcept ;
(seit C++11)
(constexpr seit C++20)

Ruft, falls möglich, die maximal theoretisch mögliche Allokationsgröße vom Allokator a ab, durch Aufruf von a. max_size ( ) .

Falls das Obige nicht möglich ist (z.B., Alloc besitzt nicht die Memberfunktion max_size() ), dann wird std:: numeric_limits < size_type > :: max ( ) / sizeof ( value_type ) zurückgegeben.

Inhaltsverzeichnis

Parameter

a - zu erkennender Allokator

Rückgabewert

Theoretische maximale Zuordnungsgröße.

Fehlerberichte

Die folgenden verhaltensändernden Fehlerberichte wurden rückwirkend auf zuvor veröffentlichte C++-Standards angewendet.

DR Angewendet auf Verhalten wie veröffentlicht Korrektes Verhalten
LWG 2162 C++11 max_size musste nicht noexcept sein erforderlich
LWG 2466 C++11 theoretische maximale Allokationsgröße in Bytes wurde als Fallback zurückgegeben Größe in Elementen wird zurückgegeben

Beispiel

#include <iostream>
#include <memory>
#include <locale>
int main()
{
    std::allocator<short> b;
    std::allocator<int> d;
    const auto p = std::allocator_traits<decltype(b)>::max_size(b);
    const auto q = std::allocator_traits<decltype(d)>::max_size(d);
    std::cout.imbue(std::locale("en_US.UTF-8"));
    std::cout << std::uppercase
              << "p = " << std::dec << p << " = 0x" << std::hex << p << '\n'
              << "q = " << std::dec << q << " = 0x" << std::hex << q << '\n';
}

Mögliche Ausgabe:

p = 9,223,372,036,854,775,807 = 0x7,FFF,FFF,FFF,FFF,FFF
q = 4,611,686,018,427,387,903 = 0x3,FFF,FFF,FFF,FFF,FFF

Siehe auch

(until C++20)
gibt die größtmögliche unterstützte Allokationsgröße zurück
(öffentliche Elementfunktion von std::allocator<T> )