1// operator new(unsigned) 2// operator new[](unsigned) 3// operator new(unsigned, std::nothrow_t const&) 4// operator new[](unsigned, std::nothrow_t const&) 5 6#include <stdlib.h> 7 8#include <new> 9 10using std::nothrow_t; 11 12// A big structure. Its details don't matter. 13typedef struct { 14 int array[1000]; 15 } s; 16 17__attribute__((noinline)) void* operator new (std::size_t n) throw (std::bad_alloc) 18{ 19 return malloc(n); 20} 21 22__attribute__((noinline)) void* operator new (std::size_t n, std::nothrow_t const &) throw () 23{ 24 return malloc(n); 25} 26 27__attribute__((noinline)) void* operator new[] (std::size_t n) throw (std::bad_alloc) 28{ 29 return malloc(n); 30} 31 32__attribute__((noinline)) void* operator new[] (std::size_t n, std::nothrow_t const &) throw () 33{ 34 return malloc(n); 35} 36 37__attribute__((noinline)) void operator delete (void* p) throw() 38{ 39 return free(p); 40} 41 42__attribute__((noinline)) void operator delete[] (void* p) throw() 43{ 44 return free(p); 45} 46 47int main(void) 48{ 49 s* p1 = new s; 50 s* p2 = new (std::nothrow) s; 51 char* c1 = new char[2000]; 52 char* c2 = new (std::nothrow) char[2000]; 53 delete p1; 54 delete p2; 55 delete [] c1; 56 delete [] c2; 57 return 0; 58} 59 60 61