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


set::get_allocator

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

allocator_type get_allocator( ) const;

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

Распределитель набором, используемый для управления памятью, параметр Allocator шаблона.

Дополнительные сведения о Allocator см. в подразделе Класс set раздела комментария.

Заметки

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

Пример

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

int main( )
{
   using namespace std;
   set <int>::allocator_type s1_Alloc;
   set <int>::allocator_type s2_Alloc;
   set <double>::allocator_type s3_Alloc;
   set <int>::allocator_type s4_Alloc;

   // The following lines declare objects
   // that use the default allocator.
   set <int> s1;
   set <int, allocator<int> > s2;
   set <double, allocator<double> > s3;

   s1_Alloc = s1.get_allocator( );
   s2_Alloc = s2.get_allocator( );
   s3_Alloc = s3.get_allocator( );

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

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

   // The following line creates a set s4
   // with the allocator of multiset s1.
   set <int> s4( less<int>( ), s1_Alloc );

   s4_Alloc = s4.get_allocator( );

   // Two allocators are interchangeable if
   // storage allocated from each can be
   // deallocated by the other
   if( s1_Alloc == s4_Alloc )
   {
      cout << "\nThe allocators are interchangeable."
           << endl;
   }
   else
   {
      cout << "\nThe 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.

The allocators are interchangeable.

Требования

Заголовок:<set>

Пространство имен: std

См. также

Ссылки

Класс set

Библиотека стандартных шаблонов