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)
Défini dans l'en-tête <memory>
static size_type max_size ( const Alloc & a ) noexcept ;
(depuis C++11)
(constexpr depuis C++20)

Si possible, obtient la taille d'allocation maximale théoriquement possible de l'allocateur a , en appelant a. max_size ( ) .

Si ce qui précède n'est pas possible (par exemple, Alloc ne possède pas la fonction membre max_size() ), alors retourne std:: numeric_limits < size_type > :: max ( ) / sizeof ( value_type ) .

Table des matières

Paramètres

a - allocateur à détecter

Valeur de retour

Taille d'allocation théorique maximale.

Rapports de défauts

Les rapports de défauts modifiant le comportement suivants ont été appliqués rétroactivement aux normes C++ précédemment publiées.

DR Applicable à Comportement publié Comportement corrigé
LWG 2162 C++11 max_size n'était pas requis d'être noexcept requis
LWG 2466 C++11 la taille d'allocation maximale théorique en octets était renvoyée comme solution de repli la taille en éléments est renvoyée

Exemple

#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';
}

Sortie possible :

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

Voir aussi

(until C++20)
retourne la taille d'allocation maximale supportée
(fonction membre publique de std::allocator<T> )