共用方式為


hash_multiset::get_allocator

注意事項注意事項

這個 API 已經過時。替代方案是 unordered_multiset 類別

傳回用來配置器物件的複製建構 hash_multiset。

Allocator get_allocator( ) const;

傳回值

hash_multiset 用來配置器處理記憶體中,是類別的範本參數的 Allocator

如需 Allocator,請參閱 hash_multiset 類別 主題的 < 備註 > 一節。

備註

hash_multiset 類別的配置器指定類別如何處理儲存區。 預設配置器提供 STL 容器類別中大部分的程式設計需要即可。 撰寫和使用的配置器類別是進階 C++ 主題。

在 Visual C++ .NET 2003 中, <hash_map><hash_set> 標頭檔的成員不在 std 命名空間中,而是移至 stdext 命名空間。 如需詳細資訊,請參閱 stdext 命名空間

範例

// hash_multiset_get_allocator.cpp
// compile with: /EHsc
#include <hash_set>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;

   // The following lines declare objects
   // that use the default allocator.
   hash_multiset <int, hash_compare <int, less<int> > > hms1;
   hash_multiset <int, hash_compare <int, greater<int> > > hms2;
   hash_multiset <double, hash_compare <double,
      less<double> >, allocator<double> > hms3;

   hash_multiset <int, hash_compare <int,
      greater<int> > >::allocator_type hms2_Alloc;
   hash_multiset <double>::allocator_type hms3_Alloc;
   hms2_Alloc = hms2.get_allocator( );

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

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

   // The following lines create a hash_multiset hms4
   // with the allocator of hash_multiset hms1.
   hash_multiset <int>::allocator_type hms4_Alloc;
   hash_multiset <int> hms4;
   hms4_Alloc = hms2.get_allocator( );

   // Two allocators are interchangeable if
   // storage allocated from each can be
   // deallocated by the other
   if( hms2_Alloc == hms4_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: 1073741823.
The number of doubles that can be allocated
before free memory is exhausted: 536870911.
The allocators are interchangeable.

需求

標頭: <hash_set>

**命名空間:**stdext

請參閱

參考

hash_multiset 類別

標準樣板程式庫