std::set_new_handler
Aus cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
definiert in Header <new>
|
||
std::new_handler set_new_handler(std::new_handler new_p) |
||
Macht
new_p
die neue globale new-Handler-Funktion und gibt den zuvor installierten new-Handler .Original:
Makes
new_p
the new global new-handler function and returns the previously installed new-handler.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Inhaltsverzeichnis |
[Bearbeiten] Notes
Das new-Handler ist die Funktion von <div class="t-tr-text">Zuordnungsfunktionen
aufgerufen, wenn eine Speicherzuweisung fehlschlägt. Seine Zweckbestimmung ist eines von drei Dingen:Original:
allocation functions
The text has been machine-translated via [http://translate.google.com Google Translate].
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
Original:
The new-handler function is the function called by
Zuordnungsfunktionen</div> whenever a memory allocation attempt fails. Its intended purpose is one of three things:
Original:
allocation functions
The text has been machine-translated via [http://translate.google.com Google Translate].
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
mehr Arbeitsspeicher zur Verfügung
2) Original:
make more memory available
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
beenden Sie das Programm (z. B. durch Berufung std::terminate)
3) Original:
terminate the program (e.g. by calling std::terminate)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
werfen Ausnahme des Typs std::bad_alloc oder aus std::bad_alloc
Original:
throw exception of type std::bad_alloc or derived from std::bad_alloc
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Wenn new-Handler kehrt wiederholt die Zuweisung Funktion die zuvor gescheitert Allokation Versuch und ruft die new-Handler wieder, wenn die Zuordnung erneut fehlschlägt. Um die Schleife zu beenden, new-Handler nennen std::set_new_handler(nullptr): wenn nach einer fehlgeschlagenen Allokation Versuch findet Allocation-Funktion, die std::get_new_handler eine Null-Zeiger-Wert zurückgibt, wird es std::bad_alloc werfen .
Original:
If new-handler returns, the allocation function repeats the previously-failed allocation attempt and calls the new-handler again if the allocation fails again. To end the loop, new-handler may call std::set_new_handler(nullptr): if, after a failed allocation attempt, allocation function finds that std::get_new_handler returns a null pointer value, it will throw std::bad_alloc.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Beim Programmstart, new-Handler ist ein NULL-Zeiger .
Original:
At program startup, new-handler is a null pointer.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten] Parameter
new_p | - | Zeiger vom Typ std::new_handler oder Null-Zeiger funktionieren
Original: pointer to function of type std::new_handler, or null pointer The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[Bearbeiten] Rückgabewert
Die vorher installierten neuen Handler oder eine Null-Zeiger-Wert, wenn keiner installiert wurde .
Original:
The previously-installed new handler, or a null pointer value if none was installed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten] Ausnahmen
[Bearbeiten] Beispiel
#include <iostream> #include <new> void handler() { std::cout << "Memory allocation failed, terminating\n"; std::set_new_handler(nullptr); } int main() { std::set_new_handler(handler); try { while(true) new int[100000000ul]; }catch(const std::bad_alloc& e) { std::cout << e.what() << '\n'; } }
Output:
Memory allocation failed, terminating std::bad_alloc
[Bearbeiten] Siehe auch
Speicheranforderungsfunktion (Funktion) | |
set_new_handler |
registriert einen neuen Funktionszeiger auf die Allokationsfunktion (Funktion) |
Typ des Funktionszeiger für new (typedef) | |
Ausnahme bei Fehlschlag der Speicherzuweisung (Klasse) |