????4. new??delete
????C++?????????????????????new?????????????棬?????·????????й??????new???????????к????????????????????????????????????
?????????????new??delete?????????????и????????????new????
????string* sp = new string("initialized")
??????????????????????????衣?????????????????operator new???????????????????????δ?????????棬???????????????????????????????и????????????????????????????????????????????·???????????????
????delete sp;
?????????delete????delete sp??????????????????????????????衣???????sp????????????????????????????????operator delete?????????????????????檔
????5. ???new-handler?????
??????operator new?????????????????????????????????????????????null????Щ??????????????????????????????t??????
??????operator new????????????δ?????????????????????????????????????????????????????ν??new-handler???????????“?????????治??”?????????????????set_new_handler???????????<new>?????????????
<span style="font-size:12px;">namespace std{
typedef void (* new_handler)();
new_handler set_new_handler(new_handler p) throw();
}</span>
????new_handler?????????????????????????
<span style="font-size:12px;">void * operator new(std::size_t size) throw(std::bad_alloc){
using namespace std;
if(size==0)  size=1;
while(true){
???????size byte;
if(success) return a pointor;
//if failed
new_handler globalHandler=set_new_handler(0); //????????new_handler
set_new_handler(globalHandler);
if(globalHandler) (*globalHandler)();
else throw std::bad_alloc();
}
}</span>
???????????????new-handler??????????????????:
???????????????????á???????operator new????????????????????????
????????????new-handler??????????new-handler??????????????棬????????????????new-handler?д????????????????????new-handler?????????????new-operator???滻?????????set_new_handler????
????ж??new-handler?????null?????set_new_handler???????а???κ?new_handler?? operator new?????????????????????
???????bad_alloc??????????bad_alloc????????
??????????????????abort??exit