Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
946 B

  1. //***************************************************************************
  2. //
  3. // NewThrow.CPP
  4. //
  5. // Module: Common new/delete w/throw
  6. //
  7. // Copyright (c) 1998-2001 Microsoft Corporation, All Rights Reserved
  8. //
  9. //***************************************************************************
  10. #include <windows.h>
  11. #include <malloc.h>
  12. #include <provexce.h>
  13. void* __cdecl operator new( size_t n)
  14. {
  15. void *ptr = malloc( n );
  16. if (!ptr)
  17. {
  18. throw CHeap_Exception(CHeap_Exception::HEAP_ERROR::E_ALLOCATION_ERROR);
  19. }
  20. return ptr;
  21. }
  22. void* __cdecl operator new[]( size_t n)
  23. {
  24. void *ptr = malloc( n );
  25. if (!ptr)
  26. {
  27. throw CHeap_Exception(CHeap_Exception::HEAP_ERROR::E_ALLOCATION_ERROR);
  28. }
  29. return ptr;
  30. }
  31. void __cdecl operator delete( void *ptr )
  32. {
  33. if (ptr)
  34. {
  35. free( ptr );
  36. }
  37. }
  38. void __cdecl operator delete[]( void *ptr )
  39. {
  40. if (ptr)
  41. {
  42. free( ptr );
  43. }
  44. }