次の方法で共有


allocator::max_size

free なメモリを簡単果される前にクラスのアロケーターのオブジェクトによって割り当てることができる型 [種類] の要素数を返します。

size_type max_size( ) const;

戻り値

割り当てることができる要素の数。

使用例

// allocator_max_size.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
#include <vector>

using namespace std;

int main( ) 
{
   vector <int> v1;
   vector <int>::iterator v1Iter;
   vector <int>:: allocator_type v1Alloc;

   int i;
   for ( i = 1 ; i <= 7 ; i++ )
   {
      v1.push_back( i );
   }

   cout << "The original vector v1 is:\n ( " ;
   for ( v1Iter = v1.begin( ) ; v1Iter != v1.end( ) ; v1Iter++ )
      cout << *v1Iter << " ";
   cout << ")." << endl;

   vector <double> v2;
   vector <double> ::iterator v2Iter;
   vector <double> :: allocator_type v2Alloc;
   allocator<int>::size_type v1size;
   v1size = v1Alloc.max_size( );

   cout << "The number of integers that can be allocated before\n"
        << " the free memory in the vector v1 is used up is: "
        << v1size << "." << endl;

   int ii;
   for ( ii = 1 ; ii <= 7 ; ii++ )
   {
      v2.push_back( ii * 10.0 );
   }

   cout << "The original vector v2 is:\n ( " ;
   for ( v2Iter = v2.begin( ) ; v2Iter != v2.end( ) ; v2Iter++ )
      cout << *v2Iter << " ";
   cout << ")." << endl;
   allocator<double>::size_type v2size;
   v2size = v2Alloc.max_size( );

   cout << "The number of doubles that can be allocated before\n"
        << " the free memory in the vector v2 is used up is: "
        << v2size << "." << endl;
}

出力例

次の出力は、x86 の場合です。

The original vector v1 is:
 ( 1 2 3 4 5 6 7 ).
The number of integers that can be allocated before
 the free memory in the vector v1 is used up is: 1073741823.
The original vector v2 is:
 ( 10 20 30 40 50 60 70 ).
The number of doubles that can be allocated before
 the free memory in the vector v2 is used up is: 536870911.

必要条件

ヘッダー : <memory>

名前空間: std

参照

関連項目

allocator Class