Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

tinynew.cpp

elegantinvention Dec 6th, 2011 840 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. /* tinynew.cpp
  2.    
  3.    Overrides operators new and delete
  4.    globally to reduce code size.
  5.    
  6.    Public domain, use however you wish.
  7.    If you really need a license, consider it MIT:
  8.    http://www.opensource.org/licenses/mit-license.php
  9.    
  10.    - Eric Agan
  11.      Elegant Invention
  12.  */
  13.  
  14. #include <new>
  15. #include <malloc.h>
  16.  
  17. void* operator new(std::size_t size) {
  18.     return malloc(size);
  19. }
  20.  
  21. void* operator new[](std::size_t size) {
  22.     return malloc(size);
  23. }
  24.  
  25. void operator delete(void* ptr) {
  26.     free(ptr);
  27. }
  28.  
  29. void operator delete[](void* ptr) {
  30.     free(ptr);
  31. }
  32.  
  33. /* Optionally you can override the 'nothrow' versions as well.
  34.    This is useful if you want to catch failed allocs with your
  35.    own debug code, or keep track of heap usage for example,
  36.    rather than just eliminate exceptions.
  37.  */
  38.  
  39. void* operator new(std::size_t size, const std::nothrow_t&) {
  40.     return malloc(size);
  41. }
  42.  
  43. void* operator new[](std::size_t size, const std::nothrow_t&) {
  44.     return malloc(size);
  45. }
  46.  
  47. void operator delete(void* ptr, const std::nothrow_t&) {
  48.     free(ptr);
  49. }
  50.  
  51. void operator delete[](void* ptr, const std::nothrow_t&) {
  52.     free(ptr);
  53. }
  54.  
  55. //eof
  56.  
  57.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top