code_junkie

How do 'malloc' and 'new' work? How are they different (implementation wise)? [closed]

Nov 12th, 2011
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. new (a, b, c) TypeId;
  2.  
  3. // the function called by the compiler has to have the following signature:
  4. operator new(std::size_t size, TypeOfA a, TypeOfB b, TypeOf C c);
  5.  
  6. new (std::nothrow) TypeId;
  7.  
  8. // the following function is defined implicitly in the standard library
  9. void * operator(std::size_t size, void * ptr) throw() {
  10. return ptr;
  11. }
  12.  
  13. new (a, b, c) TypeId;
  14.  
  15. int * a = new int;
  16. => void * operator new(std::size_t size) throw(std::bad_alloc);
  17. delete a;
  18. => void operator delete(void * ptr) throw();
  19.  
  20. TypeWhosCtorThrows * a = new ("argument") TypeWhosCtorThrows;
  21. => void * operator new(std::size_t size, char const* arg1) throw(std::bad_alloc);
  22. => void operator delete(void * ptr, char const* arg1) throw();
  23.  
  24. TypeWhosCtorDoesntThrow * a = new ("argument") TypeWhosCtorDoesntThrow;
  25. => void * operator new(std::size_t size, char const* arg1) throw(std::bad_alloc);
  26. delete a;
  27. => void operator delete(void * ptr) throw();
  28.  
  29. new (possible_arguments) TypeId[N];
Add Comment
Please, Sign In to add comment