No Description

dkgl_new.cpp 984B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <DK.h>
  2. void* operator new (std::size_t size)
  3. {
  4. if (size == 0)
  5. size = 1;
  6. void* p = nullptr;
  7. while ((p = DKFoundation::DKMalloc(size)) == nullptr)
  8. {
  9. std::new_handler handler = std::get_new_handler();
  10. if (handler)
  11. handler();
  12. else
  13. throw std::bad_alloc();
  14. }
  15. return p;
  16. }
  17. void* operator new(size_t size, const std::nothrow_t&) noexcept
  18. {
  19. void* p = nullptr;
  20. try
  21. {
  22. p = ::operator new(size);
  23. }
  24. catch (...) {}
  25. return p;
  26. }
  27. void* operator new[](std::size_t size)
  28. {
  29. return ::operator new(size);
  30. }
  31. void* operator new[](size_t size, const std::nothrow_t& tag) noexcept
  32. {
  33. return ::operator new(size, tag);
  34. }
  35. void operator delete (void* ptr) noexcept
  36. {
  37. if (ptr)
  38. DKFoundation::DKFree(ptr);
  39. }
  40. void operator delete (void* ptr, const std::nothrow_t&) noexcept
  41. {
  42. ::operator delete(ptr);
  43. }
  44. void operator delete[](void* ptr) noexcept
  45. {
  46. ::operator delete(ptr);
  47. }
  48. void operator delete[](void* ptr, const std::nothrow_t&) noexcept
  49. {
  50. ::operator delete(ptr);
  51. }