// // new_scalar.cpp // // Copyright (c) Microsoft Corporation. All rights reserved. // // Defines the scalar operator new. // #include #include #include // Enable the compiler to elide null checks during LTCG #pragma comment(linker, "/ThrowingNew") //////////////////////////////////// // new() Fallback Ordering // // +----------+ // |new_scalar<---------------+ // +----^-----+ | // | | // +----+-------------+ +----+----+ // |new_scalar_nothrow| |new_array| // +------------------+ +----^----+ // | // +------------+----+ // |new_array_nothrow| // +-----------------+ _NODISCARD _Ret_notnull_ _Post_writable_byte_size_(size) _VCRT_ALLOCATOR _CRT_SECURITYCRITICAL_ATTRIBUTE void* __CRTDECL operator new(size_t const size) { for (;;) { if (void* const block = malloc(size)) { return block; } if (_callnewh(size) == 0) { if (size == SIZE_MAX) { __scrt_throw_std_bad_array_new_length(); } else { __scrt_throw_std_bad_alloc(); } } // The new handler was successful; try to allocate again... } }