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

标准模板库