set::get_allocator

傳回用來配置器物件的複本建構這個集合。

allocator_type get_allocator( ) const;

傳回值

設定用來的配置器處理序記憶體,是樣板參數 Allocator

如需 Allocator的詳細資訊,請參閱 set Class 主題的「備註」一節。

備註

集合類別的配置器指定類別如何處理儲存區。預設配置器提供 STL 容器類別適用於大部分的程式設計需求是否足夠。擁有配置器類別的撰寫和使用為進階 C++ 的主題。

範例

// set_get_allocator.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int>::allocator_type s1_Alloc;
   set <int>::allocator_type s2_Alloc;
   set <double>::allocator_type s3_Alloc;
   set <int>::allocator_type s4_Alloc;

   // The following lines declare objects
   // that use the default allocator.
   set <int> s1;
   set <int, allocator<int> > s2;
   set <double, allocator<double> > s3;

   s1_Alloc = s1.get_allocator( );
   s2_Alloc = s2.get_allocator( );
   s3_Alloc = s3.get_allocator( );

   cout << "The number of integers that can be allocated"
        << endl << "before free memory is exhausted: "
        << s2.max_size( ) << "." << endl;

   cout << "\nThe number of doubles that can be allocated"
        << endl << "before free memory is exhausted: "
        << s3.max_size( ) <<  "." << endl;

   // The following line creates a set s4
   // with the allocator of multiset s1.
   set <int> s4( less<int>( ), s1_Alloc );

   s4_Alloc = s4.get_allocator( );

   // Two allocators are interchangeable if
   // storage allocated from each can be
   // deallocated by the other
   if( s1_Alloc == s4_Alloc )
   {
      cout << "\nThe allocators are interchangeable."
           << endl;
   }
   else
   {
      cout << "\nThe allocators are not interchangeable."
           << endl;
   }
}

範例輸出

下列輸出是 x86。

The number of integers that can be allocated
before free memory is exhausted: 1073741823.

The number of doubles that can be allocated
before free memory is exhausted: 536870911.

The allocators are interchangeable.

需求

標題: <set>

命名空間: std

請參閱

參考

set Class

標準樣板程式庫