Skip to content

Latest commit

 

History

History
22 lines (19 loc) · 1.19 KB

memory_management_new_expression.md

File metadata and controls

22 lines (19 loc) · 1.19 KB

New expression and operator new

new expression does 3 things:

  • sizeof(T) bytes allocation on a heap (via proper operator new)
  • T’s constructor call on allocated memory
  • the memory address assignment to the pointer
// replaceable allocation functions
void* operator new ( std::size_t count );
void* operator new[]( std::size_t count );
// replaceable non-throwing allocation functions
void* operator new ( std::size_t count, const std::nothrow_t& tag);
void* operator new[]( std::size_t count, const std::nothrow_t& tag);
// user-defined placement allocation functions
void* operator new ( std::size_t count, user-defined-args... );
void* operator new[]( std::size_t count, user-defined-args... );
// additional param std::align_val_t since C++17, [[nodiscard]] since C++20
// some more versions on https://en.cppreference.com/w/cpp/memory/new/operator_new