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 10 using std::nothrow_t; 11 12 // A big structure. Its details don't matter. 13 typedef struct { 14 int array[1000]; 15 } s; 16 operator new(std::size_t n)17__attribute__((noinline)) void* operator new (std::size_t n) 18 { 19 return malloc(n); 20 } 21 operator new(std::size_t n,std::nothrow_t const &)22__attribute__((noinline)) void* operator new (std::size_t n, std::nothrow_t const &) 23 { 24 return malloc(n); 25 } 26 operator new[](std::size_t n)27__attribute__((noinline)) void* operator new[] (std::size_t n) 28 { 29 return malloc(n); 30 } 31 operator new[](std::size_t n,std::nothrow_t const &)32__attribute__((noinline)) void* operator new[] (std::size_t n, std::nothrow_t const &) 33 { 34 return malloc(n); 35 } 36 operator delete(void * p)37__attribute__((noinline)) void operator delete (void* p) 38 { 39 return free(p); 40 } 41 operator delete[](void * p)42__attribute__((noinline)) void operator delete[] (void* p) 43 { 44 return free(p); 45 } 46 main(void)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