Espaços nominais
Variantes
Ações

std::set_new_handler

De cppreference.com
< cpp | memory | new

<metanoindex/>

 
 
Biblioteca de utilitários
Digite apoio (basic types, RTTI, type traits)
Gerenciamento de memória dinâmica
De tratamento de erros
Utilidades do programa
Variadic funções
Data e hora
Objetos de função
(C++11)
Os operadores relacionais
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
Pares e tuplas
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
Troque, avançar e avançar
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
 
Gerenciamento de memória dinâmica
Gerenciamento de memória de baixo nível
Alocadores
Original:
Allocators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Uninitialized armazenamento
Original:
Uninitialized storage
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Ponteiros inteligentes
Original:
Smart pointers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
(obsoleta)
(C++11)
Apoio a coleta de lixo
Original:
Garbage collection support
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Diversos
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
C Library
Original:
C Library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Gerenciamento de memória de baixo nível
Funções
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Classes
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Objetos
Original:
Objects
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
<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.

Notas

O' nova função-manipulador é a função chamada por
funções de alocação
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.
sempre uma tentativa de alocação de memória falhar. Sua finalidade é uma de três coisas:
Original:
The text has been machine-translated via Google Translate.
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.

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.

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.
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.
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.

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.

Exceções

noexcept specification:  
<tbody> </tbody>
noexcept
  (desde C++11)

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) [edit]
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) [edit]
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) [edit]
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) [edit]