Поделиться через


hash_multimap::get_allocator

ПримечаниеПримечание

Этот API устарел.Альтернативы unordered_multimap Class.

Возвращает копию объекта выделения, используемого для построения hash_multimap.

Allocator get_allocator( ) const;

Возвращаемое значение

Механизм распределения, используемый hash_multimap.

Заметки

Allocators для класса hash_multimap определяют, как класс управляет хранением.По умолчанию allocators, поставляемые с классами контейнеров STL достаточны для большинства необходимостей программирования.Создание и использование собственного класса распределитель раздел дополнительно C++.

В Visual C++ .NET 2003 <hash_map> элементы файлов заголовков и <hash_set> больше не находятся в пространстве имен std, но скорее перейти на пространство имен stdext.Дополнительные сведения см. в разделе Пространство имен stdext.

Пример

// hash_multimap_get_allocator.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   hash_multimap <int, int>::allocator_type hm1_Alloc;
   hash_multimap <int, int>::allocator_type hm2_Alloc;
   hash_multimap <int, double>::allocator_type hm3_Alloc;
   hash_multimap <int, int>::allocator_type hm4_Alloc;

   // The following lines declare objects
   // that use the default allocator.
   hash_multimap <int, int> hm1;
   hash_multimap <int, int> hm2;
   hash_multimap <int, double> hm3;

   hm1_Alloc = hm1.get_allocator( );
   hm2_Alloc = hm2.get_allocator( );
   hm3_Alloc = hm3.get_allocator( );

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

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

   // The following line creates a hash_multimap hm4
   // with the allocator of hash_multimap hm1.
   hash_multimap <int, int> hm4( less<int>( ), hm1_Alloc );

   hm4_Alloc = hm4.get_allocator( );

   // Two allocators are interchangeable if
   // storage allocated from each can be
   // deallocated by the other
   if( hm1_Alloc == hm4_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.

Требования

заголовок: <hash_map>

Stdext пространство имен:

См. также

Ссылки

hash_multimap Class

Стандартная библиотека шаблонов