다음을 통해 공유


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;
   }
}

샘플 출력

다음 출력에 대 한 x 86입니다.

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 Class

표준 템플릿 라이브러리