Skip to content

Latest commit

 

History

History
61 lines (43 loc) · 2.82 KB

set-new-mode.md

File metadata and controls

61 lines (43 loc) · 2.82 KB
description title ms.date api_name api_location api_type topic_type f1_keywords helpviewer_keywords ms.assetid
Learn more about: _set_new_mode
_set_new_mode
4/2/2020
_set_new_mode
_o__set_new_mode
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-heap-l1-1-0.dll
DLLExport
apiref
set_new_mode
_set_new_mode
handler modes
_set_new_mode function
set_new_mode function
4d14039a-e54e-4689-8c70-74a4b9834768

_set_new_mode

Sets a new handler mode for malloc.

Syntax

int _set_new_mode( int newhandlermode );

Parameters

newhandlermode
new handler mode for malloc; valid value is 0 or 1.

Return value

Returns the previous handler mode set for malloc. A return value of 1 indicates that, on failure to allocate memory, malloc previously called the new handler routine; a return value of 0 indicates that it didn't. If the newhandlermode argument doesn't equal 0 or 1, returns -1.

Remarks

The C++ _set_new_mode function sets the new handler mode for malloc. The new handler mode indicates whether, on failure, malloc is to call the new handler routine as set by _set_new_handler. By default, malloc doesn't call the new handler routine on failure to allocate memory. You can override this default behavior so that, when malloc fails to allocate memory, malloc calls the new handler routine in the same way that the new operator does when it fails for the same reason. For more information, see the new and delete operators in the C++ Language Reference. To override the default, call:

_set_new_mode(1);

early in your program or link with Newmode.obj (see Link options).

This function validates its parameter. If newhandlermode is anything other than 0 or 1, the function invokes the invalid parameter handler, as described in Parameter validation. If execution is allowed to continue, _set_new_mode returns -1 and sets errno to EINVAL.

By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.

Requirements

Routine Required header
_set_new_mode <new.h>

For more compatibility information, see Compatibility.

See also

Memory allocation
calloc
free
realloc
_query_new_handler
_query_new_mode