No Description

dkgl_new.cpp 875B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 delete (void* ptr) noexcept
  32. {
  33. if (ptr)
  34. DKFoundation::DKFree(ptr);
  35. }
  36. void operator delete (void* ptr, const std::nothrow_t&) noexcept
  37. {
  38. ::operator delete(ptr);
  39. }
  40. void operator delete[](void* ptr) noexcept
  41. {
  42. ::operator delete(ptr);
  43. }
  44. void operator delete[](void* ptr, const std::nothrow_t&) noexcept
  45. {
  46. ::operator delete(ptr);
  47. }