Freigeben über


hash_set::get_allocator

HinweisHinweis

Diese API ist veraltet.Die Alternative ist unordered_set Class.

Gibt eine Kopie des allocator-Objekts zurück, das verwendet wird, um das hash_set zu erstellen.

Allocator get_allocator( ) const;

Rückgabewert

Die Belegungsfunktion wird vom hash_set, um Speicherplatz zu verwalten, der der Vorlagenparameter Allocator ist.

Weitere Informationen zu Allocator, finden Sie in den Hinweisen hash_set Class des Themas.

Hinweise

Belegungsfunktionen für die hash_set Klasse geben an, wie die Klasse Speicher verwaltet.Die standardmäßige Belegungsfunktionen, die mit STL-Containerklassen angegeben wird, ist für die meisten Programmierung Anforderungen genügen.Ihre eigene allocator-Klasse zu schreiben und die Anwendung ist ein erweitertes C++-Thema.

In Visual C++ .NET 2003, sind Member der <hash_map> und <hash_set> Headerdateien nicht mehr im stdnamespace, sondern sind in den stdext Namespace verschoben wurde.Weitere Informationen finden Sie unter Der stdext-Namespace.

Beispiel

// hash_set_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_set <int, hash_compare <int, less<int> > > hs1;
   hash_set <int,  hash_compare <int, greater<int> > > hs2;
   hash_set <double, hash_compare <double,
      less<double> >, allocator<double> > hs3;

   hash_set <int, hash_compare <int,
      greater<int> > >::allocator_type hs2_Alloc;
   hash_set <double>::allocator_type hs3_Alloc;
   hs2_Alloc = hs2.get_allocator( );

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

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

   // The following lines create a hash_set hs4
   // with the allocator of hash_set hs1.
   hash_set <int>::allocator_type hs4_Alloc;
   hash_set <int> hs4;
   hs4_Alloc = hs2.get_allocator( );

   // Two allocators are interchangeable if
   // storage allocated from each can be
   // deallocated by the other
   if( hs2_Alloc == hs4_Alloc )
   {
      cout << "The allocators are interchangeable."
           << endl;
   }
   else
   {
      cout << "The allocators are not interchangeable."
           << endl;
   }
}

Beispielausgabe

Die folgende Ausgabe ist für 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.

Anforderungen

Header: <hash_set>

Namespace: stdext

Siehe auch

Referenz

hash_set Class

Standardvorlagenbibliothek