Compartilhar via


multimap::get_allocator

Retorna uma cópia do distribuidor usado para construir o multimap.

allocator_type get_allocator( ) const;

Valor de retorno

O distribuidor usado pelo multimap.

Comentários

Os distribuidores para a classe de multimap especificam como a classe gerencia o armazenamento.Os distribuidores padrão fornecidos com classes do contêiner de STL são suficientes para a maioria das necessidades de programação.Escrever e usar sua própria classe do distribuidor é um tópico avançada do C++.

Exemplo

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

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

   // The following lines declare objects
   // that use the default allocator.
   multimap <int, int> m1;
   multimap <int, int, allocator<int> > m2;
   multimap <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"
        << endl << "before free memory is exhausted: "
        << m2.max_size( ) << ".\n" << endl;

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

   // The following line creates a multimap m4
   // with the allocator of multimap 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 via the other
   if( m1_Alloc == m4_Alloc )
   {
      cout << "The allocators are interchangeable."
           << endl;
   }
   else   
   {
      cout << "The allocators are not interchangeable."
           << endl;
   }
}

A saída de exemplo

A saída a seguir são para x.

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.

Requisitos

Cabeçalho: <map>

namespace: STD

Consulte também

Referência

multimap Class

Standard Template Library