Standard library header <new> - cppreference.com

From cppreference.com

This header is part of the

dynamic memory management

library, in particular provides

low level memory management

features.

Classes

bad_alloc

exception thrown when memory allocation fails
(class)

[edit]

bad_array_new_length

(C++11)

exception thrown on allocation of array with invalid length
(class)

[edit]

align_val_t

(C++17)

type used to pass alignment to alignment-aware allocation and deallocation functions
(enum)

[edit]

Types

new_handler

function pointer type of the new handler
(typedef)

[edit]

Tags

nothrownothrow_t

a tag used to select a non-throwing allocation function
(tag)

[edit]

destroying_deletedestroying_delete_t

(C++20)

a tag used to select destroying-delete overloads of

operator delete

(tag)

[edit]

Constants

hardware_destructive_interference_sizehardware_constructive_interference_size

(C++17)

min offset to avoid false sharing
max offset to promote true sharing
(constant)

[edit]

Functions

operator newoperator new[]

allocation functions
(function)

[edit]

operator deleteoperator delete[]

deallocation functions
(function)

[edit]

get_new_handler

(C++11)

obtains the current new handler
(function)

[edit]

set_new_handler

registers a new handler
(function)

[edit]

launder

(C++17)

pointer optimization barrier
(function template)

[edit]

Synopsis

// all freestandingnamespacestd{// storage allocation errorsclassbad_alloc;classbad_array_new_length;structdestroying_delete_t{explicitdestroying_delete_t()=default;};inlineconstexprdestroying_delete_tdestroying_delete{};// global operator new controlenumclassalign_val_t:size_t{};structnothrow_t{explicitnothrow_t()=default;};externconstnothrow_tnothrow;usingnew_handler=void(*)();new_handlerget_new_handler()noexcept;new_handlerset_new_handler(new_handlernew_p)noexcept;// pointer optimization barriertemplate<classT>constexprT*launder(T*p)noexcept;// hardware interference sizeinlineconstexprsize_thardware_destructive_interference_size=/* implementation-defined */;inlineconstexprsize_thardware_constructive_interference_size=/* implementation-defined */;}// storage allocation and deallocationvoid*operatornew(std::size_tsize);void*operatornew(std::size_tsize,std::align_val_talignment);void*operatornew(std::size_tsize,conststd::nothrow_t&)noexcept;void*operatornew(std::size_tsize,std::align_val_talignment,conststd::nothrow_t&)noexcept;voidoperatordelete(void*ptr)noexcept;voidoperatordelete(void*ptr,std::size_tsize)noexcept;voidoperatordelete(void*ptr,std::align_val_talignment)noexcept;voidoperatordelete(void*ptr,std::size_tsize,std::align_val_talignment)noexcept;voidoperatordelete(void*ptr,conststd::nothrow_t&)noexcept;voidoperatordelete(void*ptr,std::align_val_talignment,conststd::nothrow_t&)noexcept;void*operatornew[](std::size_tsize);void*operatornew[](std::size_tsize,std::align_val_talignment);void*operatornew[](std::size_tsize,conststd::nothrow_t&)noexcept;void*operatornew[](std::size_tsize,std::align_val_talignment,conststd::nothrow_t&)noexcept;voidoperatordelete[](void*ptr)noexcept;voidoperatordelete[](void*ptr,std::size_tsize)noexcept;voidoperatordelete[](void*ptr,std::align_val_talignment)noexcept;voidoperatordelete[](void*ptr,std::size_tsize,std::align_val_talignment)noexcept;voidoperatordelete[](void*ptr,conststd::nothrow_t&)noexcept;voidoperatordelete[](void*ptr,std::align_val_talignment,conststd::nothrow_t&)noexcept;constexprvoid*operatornew(std::size_tsize,void*ptr)noexcept;constexprvoid*operatornew[](std::size_tsize,void*ptr)noexcept;constexprvoidoperatordelete(void*ptr,void*)noexcept;constexprvoidoperatordelete[](void*ptr,void*)noexcept;