扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
void *__cdecl operator new(size_t) _THROW1(std::bad_alloc); void *__cdecl operator new(size_t, const std::nothrow_t&) _THROW0(); |
#define _THROW0() throw () #define _THROW1(x) throw (x) |
void * operator new( unsigned int cb ) |
/*** *use_ansi.h - pragmas for ANSI Standard C++ libraries * * Copyright (c) 1996-1997, Microsoft Corporation. All rights reserved. * *Purpose: * This header is intended to force the use of the appropriate ANSI * Standard C++ libraries whenever it is included. * * [Public] * ****/ #if _MSC_VER > 1000 #pragma once #endif #ifndef _USE_ANSI_CPP #define _USE_ANSI_CPP #ifdef _MT #ifdef _DLL #ifdef _DEBUG #pragma comment(lib,"msvcprtd") #else // _DEBUG #pragma comment(lib,"msvcprt") #endif // _DEBUG #else // _DLL #ifdef _DEBUG #pragma comment(lib,"libcpmtd") #else // _DEBUG #pragma comment(lib,"libcpmt") #endif // _DEBUG #endif // _DLL #else // _MT #ifdef _DEBUG #pragma comment(lib,"libcpd") #else // _DEBUG #pragma comment(lib,"libcp") #endif // _DEBUG #endif #endif // _USE_ANSI_CPP |
// test.cpp #include <new> #include <iostream> using namespace std; class BigClass { public: BigClass() {} ~BigClass(){} char BigArray[0x7FFFFFFF]; }; int main() { try { BigClass *p = new BigClass; } catch( bad_alloc &a) { cout << "new BigClass, threw a bad_alloc exception" << endl; } BigClass *q = new(nothrow) BigClass; if ( q == NULL ) cout << "new(nothrow) BigClass, returned a NULL pointer" << endl; try { BigClass *r = new BigClass[1]; } catch( bad_alloc &a) { cout << "new BigClass[1], threw a bad_alloc exception" << endl; } return 0; } |
new(nothrow) BigClass, returned a NULL pointer |
dumpbin /SYMBOLS libcp.lib |
#if !defined(_MSC_EXTENSIONS) ... ... void *__cdecl operator new(size_t size) _THROW1(_STD bad_alloc) { ... ... } #endif |
#include <dbgint.h> |
#include "dbgint.h" |
cl /c /Za /D_CRTBLD newop.cpp |
#ifndef _CRTBLD /* * This is an internal C runtime header file. It is used when building * the C runtimes only. It is not to be used as a public header file. */ #error ERROR: Use of C runtime library internal header file. #endif /* _CRTBLD */ |
cl /c /GX test.cpp |
link test.obj newop.obj |
new BigClass, threw a bad_alloc exception new(nothrow) BigClass, returned a NULL pointer new BigClass[1], threw a bad_alloc exception |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者