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.

89 lines
2.3 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. #ifdef DEBUG /*** THIS WHOLE FILE ***/
  4. unsigned long g_BreakAlloc = (unsigned long)-1;
  5. /* U P D A T E C R T D B G S E T T I N G S */
  6. /*-------------------------------------------------------------------------
  7. %%Function: UpdateCrtDbgSettings
  8. Update the C runtime debug memory settings
  9. -------------------------------------------------------------------------*/
  10. VOID UpdateCrtDbgSettings(void)
  11. {
  12. #if 0
  13. // This depends on the use of the debug c runtime library
  14. int tmpFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
  15. // Always enable memory leak checking debug spew
  16. // tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
  17. // Release memory just like the retail version
  18. tmpFlag &= ~_CRTDBG_DELAY_FREE_MEM_DF;
  19. // Don't bother checking the entire heap
  20. tmpFlag &= ~_CRTDBG_CHECK_ALWAYS_DF;
  21. _CrtSetDbgFlag(tmpFlag);
  22. #endif // 0
  23. }
  24. #if 0
  25. int _cdecl MyAllocHook ( int allocType, void *userData,
  26. size_t size, int blockType,
  27. long requestNumber, const char *filename, int lineNumber )
  28. {
  29. char buf[256];
  30. wsprintf(buf, "%s {%d}: %d bytes on line %d file %s\n\r",
  31. allocType == _HOOK_ALLOC ? "ALLOC" :
  32. ( allocType == _HOOK_REALLOC ? "REALLOC" : "FREE" ),
  33. requestNumber,
  34. size, lineNumber, filename );
  35. OutputDebugString(buf);
  36. return TRUE;
  37. }
  38. #endif // 0
  39. /* I N I T D E B U G M E M O R Y O P T I O N S */
  40. /*-------------------------------------------------------------------------
  41. %%Function: InitDebugMemoryOptions
  42. Initilize the runtime memory
  43. -------------------------------------------------------------------------*/
  44. BOOL InitDebugMemoryOptions(void)
  45. {
  46. #if 0
  47. // _asm int 3; chance to set _crtBreakAlloc - use debugger or uncomment
  48. _CrtSetBreakAlloc(g_BreakAlloc);
  49. UpdateCrtDbgSettings();
  50. _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW); // create a message box on errors
  51. { // To track down memory leaks, set cAlloc to the allocation number
  52. LONG cAlloc = 0; // Allocation number
  53. if (0 != cAlloc)
  54. _CrtSetBreakAlloc(cAlloc);
  55. }
  56. #ifdef MNMSRVC_SETALLOCHOOK
  57. _CrtSetAllocHook ( MyAllocHook );
  58. #endif // MNMSRVC_SETALLOCHOOK
  59. #endif // 0
  60. return TRUE;
  61. }
  62. VOID DumpMemoryLeaksAndBreak(void)
  63. {
  64. #if 0
  65. if ( _CrtDumpMemoryLeaks() )
  66. {
  67. // _asm int 3; Uncomment to break after leak spew
  68. }
  69. #endif // 0
  70. }
  71. #endif /* DEBUG - whole file */