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.

107 lines
3.0 KiB

  1. /***
  2. *dbgnew.cpp - defines C++ new() routines, debug version
  3. *
  4. * Copyright (c) 1995-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Defines C++ new() routines.
  8. *
  9. *Revision History:
  10. * 01-12-95 CFW Initial version.
  11. * 01-19-95 CFW Need oscalls.h to get DebugBreak definition.
  12. * 01-20-95 CFW Change unsigned chars to chars.
  13. * 01-23-95 CFW Delete must check for NULL.
  14. * 02-10-95 CFW _MAC_ -> _MAC.
  15. * 03-16-95 CFW delete() only for normal, ignore blocks.
  16. * 03-21-95 CFW Add _delete_crt, _delete_client.
  17. * 03-21-95 CFW Remove _delete_crt, _delete_client.
  18. * 06-27-95 CFW Add win32s support for debug libs.
  19. * 12-28-95 JWM Split off delete() for granularity.
  20. * 05-22-98 JWM Support for KFrei's RTC work, and operator new[].
  21. * 07-28-98 JWM RTC update.
  22. * 01-05-99 GJF Changes for 64-bit size_t.
  23. * 05-26-99 KBF Updated RTC_Allocate_hook params
  24. *
  25. *******************************************************************************/
  26. #ifdef _DEBUG
  27. #include <cruntime.h>
  28. #include <malloc.h>
  29. #include <mtdll.h>
  30. #include <dbgint.h>
  31. #include <rtcsup.h>
  32. /***
  33. *void * operator new() - Get a block of memory from the debug heap
  34. *
  35. *Purpose:
  36. * Allocate of block of memory of at least size bytes from the heap and
  37. * return a pointer to it.
  38. *
  39. * Allocates any type of supported memory block.
  40. *
  41. *Entry:
  42. * size_t cb - count of bytes requested
  43. * int nBlockUse - block type
  44. * char * szFileName - file name
  45. * int nLine - line number
  46. *
  47. *Exit:
  48. * Success: Pointer to memory block
  49. * Failure: NULL (or some error value)
  50. *
  51. *Exceptions:
  52. *
  53. *******************************************************************************/
  54. void * operator new(
  55. size_t cb,
  56. int nBlockUse,
  57. const char * szFileName,
  58. int nLine
  59. )
  60. {
  61. void *res = _nh_malloc_dbg( cb, 1, nBlockUse, szFileName, nLine );
  62. RTCCALLBACK(_RTC_Allocate_hook, (res, cb, 0));
  63. return res;
  64. }
  65. /***
  66. *void * operator new() - Get a block of memory from the debug heap
  67. *
  68. *Purpose:
  69. * Allocate of block of memory of at least size bytes from the heap and
  70. * return a pointer to it.
  71. *
  72. * Allocates any type of supported memory block.
  73. *
  74. *Entry:
  75. * size_t cb - count of bytes requested
  76. * int nBlockUse - block type
  77. * char * szFileName - file name
  78. * int nLine - line number
  79. *
  80. *Exit:
  81. * Success: Pointer to memory block
  82. * Failure: NULL (or some error value)
  83. *
  84. *Exceptions:
  85. *
  86. *******************************************************************************/
  87. void * operator new[](
  88. size_t cb,
  89. int nBlockUse,
  90. const char * szFileName,
  91. int nLine
  92. )
  93. {
  94. void *res = operator new(cb, nBlockUse, szFileName, nLine );
  95. RTCCALLBACK(_RTC_Allocate_hook, (res, cb, 0));
  96. return res;
  97. }
  98. #endif /* _DEBUG */