hash_multiset::get_allocator

备注

此 API 已过时。另一种方法是 unordered_multiset Class

返回用于的分配器对象的复制构造 hash_multiset。

Allocator get_allocator( ) const;

返回值

hash_multiset 使用的分配器管理内存,是选件类的模板参数 Allocator

有关 Allocator的更多信息,请参见 hash_multiset Class 主题的"备注"节。

备注

hash_multiset 选件类的分配器指定选件类如何管理存储。 默认分配程序提供了 STL 容器选件类对于大多数编程的需要就足够了。 编写和使用您的分配器选件类是高级 C++ 主题。

在 Visual C++ .NET 2003 中,<hash_map><hash_set> 标头文件的成员中不再标准,命名空间,而是将 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 Class

标准模板库