map::get_allocator

用于返回的对象分配程序的复制构造映射。

allocator_type get_allocator( ) const;

返回值

映射使用的分配器。

备注

映射类的分配器指定类如何管理存储。 默认分配程序都附有 STL 容器类用于大多数编程的需要即可。 拥有分配编写和使用程序类是高级 C++ 主题。

示例

// map_get_allocator.cpp
// compile with: /EHsc
#include <map>
#include <iostream>

int main( )
{
   using namespace std;
   map <int, int>::allocator_type m1_Alloc;
   map <int, int>::allocator_type m2_Alloc;
   map <int, double>::allocator_type m3_Alloc;
   map <int, int>::allocator_type m4_Alloc;

   // The following lines declare objects
   // that use the default allocator.
   map <int, int> m1;
   map <int, int, allocator<int> > m2;
   map <int, double, allocator<double> > m3;

   m1_Alloc = m1.get_allocator( );
   m2_Alloc = m2.get_allocator( );
   m3_Alloc = m3.get_allocator( );

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

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

   // The following line creates a map m4
   // with the allocator of map m1.
   map <int, int> m4( less<int>( ), m1_Alloc );

   m4_Alloc = m4.get_allocator( );

   // Two allocators are interchangeable if
   // storage allocated from each can be
   // deallocated with the other
   if( m1_Alloc == m4_Alloc )   
   {
      cout << "The allocators are interchangeable." << endl;
   }
   else   
   {
      cout << "The allocators are not interchangeable." << endl;
   }
}

示例输出

将生成下面关于x86的输出。

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

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

The allocators are interchangeable.

要求

标头: <map>

命名空间: std

请参见

参考

map 类

标准模板库