1 #include <new> 2 3 using std::bad_alloc; 4 5 extern "C" void *malloc (std::size_t); 6 extern "C" void abort (void); 7 8 void * operator new(std::size_t sz,const std::nothrow_t &)9operator new (std::size_t sz, const std::nothrow_t&) throw() 10 { 11 void *p; 12 13 /* malloc (0) is unpredictable; avoid it. */ 14 if (sz == 0) 15 sz = 1; 16 p = (void *) malloc (sz); 17 return p; 18 } 19 20 void * operator new(std::size_t sz)21operator new (std::size_t sz) throw (std::bad_alloc) 22 { 23 void *p; 24 25 /* malloc (0) is unpredictable; avoid it. */ 26 if (sz == 0) 27 sz = 1; 28 p = (void *) malloc (sz); 29 while (p == 0) 30 { 31 ::abort(); 32 } 33 34 return p; 35 } 36 37 void* operator new[](std::size_t sz)38operator new[] (std::size_t sz) throw (std::bad_alloc) 39 { 40 return ::operator new(sz); 41 } 42 43 void * operator new[](std::size_t sz,const std::nothrow_t & nothrow)44operator new[] (std::size_t sz, const std::nothrow_t& nothrow) throw() 45 { 46 return ::operator new(sz, nothrow); 47 } 48