共用方式為


multiset::get_allocator

傳回用來配置器物件的複本建構多重集。

allocator_type get_allocator( ) const;

傳回值

多重集使用的配置器。

備註

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

範例

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

int main( )
{
   using namespace std;
   multiset <int>::allocator_type ms1_Alloc;
   multiset <int>::allocator_type ms2_Alloc;
   multiset <double>::allocator_type ms3_Alloc;
   multiset <int>::allocator_type ms4_Alloc;

   // The following lines declare objects
   // that use the default allocator.
   multiset <int> ms1;
   multiset <int, allocator<int> > ms2;
   multiset <double, allocator<double> > ms3;

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

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

   // The following lines create a multiset ms4
   // with the allocator of multiset ms1
   ms1_Alloc = ms1.get_allocator( );
   multiset <int> ms4( less<int>( ), ms1_Alloc );
   ms4_Alloc = ms4.get_allocator( );

   // Two allocators are interchangeable if
   // storage allocated from each can be
   // deallocated with the other
   if( ms1_Alloc == ms4_Alloc )   
   {
      cout << "Allocators are interchangeable."
           << endl;   
   }
   else   
   {
      cout << "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.
Allocators are interchangeable.

需求

標題: <set>

命名空間: std

請參閱

參考

multiset Class

標準樣板程式庫