std::set_new_handler
De 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. |
<metanoindex/>
<tbody> </tbody>| Definido no cabeçalho <new>
|
||
std::new_handler set_new_handler(std::new_handler new_p) |
||
Faz
new_p a nova função nova-manipulador global e retorna o instalado anteriormente nova-manipulador.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.
Notas
O' nova função-manipulador é a função chamada por
funções de alocação
sempre uma tentativa de alocação de memória falhar. Sua finalidade é uma de três coisas: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
funções de alocação
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.
1)
disponibilizar mais memória
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.
2)
terminar o programa (por exemplo, por std::terminate chamada)
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.
3)
jogar exceção de std::bad_alloc tipo ou derivado de 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.
Se retornos nova-manipulador, a função de alocação repete a tentativa de alocação previamente falhou e chama o novo novamente manipulador-se a alocação de falhar novamente. Para encerrar o ciclo, novo-manipulador pode chamar
std::set_new_handler(nullptr): se, depois de uma tentativa de alocação falhou, função de atribuição descobre que std::get_new_handler retorna um valor ponteiro nulo, ele vai jogar std::bad_alloc.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.
No arranque do programa, novo-manipulador é um ponteiro nulo.
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.
Parâmetros
| new_p | - | ponteiro para função de std::new_handler tipo ou ponteiro nulo
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. |
Valor de retorno
O manipulador instalada anteriormente novo, ou um valor de ponteiro nulo se nenhum foi instalado.
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.
Exceções
Exemplo
#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';
}
}
Saída:
Memory allocation failed, terminating
std::bad_alloc
Veja também
funções de alocação Original: allocation functions The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função) | |
registra um novo manipulador Original: registers a new handler The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função) | |
tipo de função ponteiro do manipulador de novo Original: function pointer type of the new handler The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (typedef) | |
exceção lançada quando a alocação de memória falha Original: exception thrown when memory allocation fails The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (classe) | |