// // 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| // +-----------------+ _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... } } /* * Copyright (c) 1992-2002 by P.J. Plauger. ALL RIGHTS RESERVED. * Consult your license regarding permissions and restrictions. V3.13:0009 */