new 一定记得delete
new typename[] 一定记得delete[]
new不一定会成功,因此可能需要有提醒机制,使用set_new_handler(void *):
// function to call if operator new can't allocate enough memory
void nomorememory()
{
cerr << "unable to satisfy request for memory\n";
abort();
}
int main()
{
set_new_handler(nomorememory);
int *pbigdataarray = new int[100000000];
...
}