/tags/jet3d_dev_msvc2003/include/jeMemAllocInfo.h

# · C Header · 170 lines · 76 code · 28 blank · 66 comment · 0 complexity · ce3808d938aab18f64047a23c57cf6d6 MD5 · raw file

  1. /****************************************************************************************/
  2. /* jeMemAllocInfo.h */
  3. /* */
  4. /* Author: David Eisele */
  5. /* Description: Extended memoryleak debugging module */
  6. /* */
  7. /* The contents of this file are subject to the Jet3D Public License */
  8. /* Version 1.02 (the "License"); you may not use this file except in */
  9. /* compliance with the License. You may obtain a copy of the License at */
  10. /* http://www.jet3d.com */
  11. /* */
  12. /* Software distributed under the License is distributed on an "AS IS" */
  13. /* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See */
  14. /* the License for the specific language governing rights and limitations */
  15. /* under the License. */
  16. /* */
  17. /* This file was not part of the original Jet3D, released December 12, 1999. */
  18. /* */
  19. /****************************************************************************************/
  20. #ifndef JE_MEMALLOCINFO_H
  21. #define JE_MEMALLOCINFO_H
  22. #define JE_DEACTIVATE_JMAI
  23. #ifdef NDEBUG
  24. #define JE_DEACTIVATE_JMAI // RELEASE COMPILE SHALL IGNORE jMAI-MODULE!!!
  25. #endif
  26. #include "BaseType.h"
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #define jMAI_CREATED (1<<0) // module created/destroyed flag
  31. #define jMAI_ACTIVE (1<<1) // turn on/off flag
  32. #define jMAI_SAVE_ON_FREE (1<<2) // save/delete infos on free flag
  33. #define jMAI_EXCLUDE_ALL_FILES (1<<3) // exclude/include all files flag
  34. #ifndef JE_DEACTIVATE_JMAI
  35. JETAPI void JETCC jeMemAllocInfo_Create(const char *FName);
  36. // This should be the very first jMAI call:
  37. // All static variables and memory structures are created and set to base values
  38. // FName : Name of Preferences file
  39. JETAPI void JETCC jeMemAllocInfo_Destroy();
  40. // This should be the final jMAI call:
  41. // All static variables and memory structures are freed/set to base values
  42. JETAPI void JETCC jeMemAllocInfo_Activate();
  43. // This function activates the jMAI-module:
  44. // Initialization:
  45. // read pref.file and set flags/included/excluded files and all breakpoints
  46. // Breakpointformat: <Filename>( <Linenumber> ) xxxx [ <Callnumber> ]
  47. // breakpoint-& dump-format are the same, so you can copy & paste lines from dump to preferences file
  48. // if no linenumber or callnumber is given, the function assumes zero
  49. // FileName : Name of sourcefile, where allocation is called
  50. // LineNr : Linenumber of allocationcall
  51. // 0 = react on every allocationcall in this file
  52. // CallNr : On which call should be stopped?
  53. // 0 = all calls
  54. // 1 = first one, 2 = second one, ...
  55. // all created pointers (with jeRam) will be registered
  56. // all set breakpoints will be activated
  57. // file/position/latest reallocation/current pointer/size will be recorded
  58. JETAPI void JETCC jeMemAllocInfo_DeActivate(jeBoolean DojMAIReport);
  59. // This function deactivates the jMAI-module:
  60. // all current (and freed, if flag was set) pointers will be reported, if DojMAIReport is JE_TRUE
  61. // (re)alloc/free infostructures will be freed
  62. // All dumps will be appended, if the file exists
  63. JETAPI void JETCC jeMemAllocInfo_FileReport(const char *FName, const char *DumpFile, jeBoolean FreedMemoryReport);
  64. // Use this to write a report of a specified source file: FName
  65. // DumpFile : Name of dumpfile
  66. // FreedMemoryReport : JE_TRUE = report freed pointers
  67. // JE_FALSE = report current pointers
  68. JETAPI uint32 JETCC jeMemAllocInfo_GetFlags();
  69. // Get current flags
  70. #else
  71. #define jeMemAllocInfo_Create(FName)
  72. #define jeMemAllocInfo_Activate()
  73. #define jeMemAllocInfo_DeActivate(DojMAIReport)
  74. #define jeMemAllocInfo_Destroy()
  75. #define jeMemAllocInfo_FileReport(FName,DumpFile,FreedMemoryReport)
  76. #define jeMemAllocInfo_GetFlags(Flags) 0
  77. #endif
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif
  82. #if 0
  83. // Sample Preferences.jMAI-file
  84. <NAMES>
  85. dumpfile="jMAI_current.dmp"
  86. freedfile="jMAI_freed.dmp"
  87. </NAMES>
  88. <FLAGS>
  89. ExcludeAllFiles=0
  90. SaveOnFree=1
  91. </FLAGS>
  92. <BREAKPOINTS>
  93. E:\jetpp\jet\src\jet\JetEngine\guWorld\jeIndexPoly.c( 40): 8 byte(s) allocated [ 12]
  94. E:\jetpp\jet\src\jet\JetEngine\guWorld\jeVertArray.c( 77)
  95. E:\jetpp\jet\src\jet\JetEngine\guWorld\jeBrush.c
  96. </BREAKPOINTS>
  97. <INCLUDE>
  98. </INCLUDE>
  99. <EXCLUDE>
  100. E:\jetpp\jet\src\jet\JetEngine\Support\jeResource.c
  101. </EXCLUDE>
  102. // EOF
  103. // Usage sample
  104. // >Editor-MFC Files-jwe.cpp<
  105. // ...
  106. #include "jeMemAllocInfo.h"
  107. //...
  108. BOOL CJweApp::InitInstance()
  109. {
  110. CString cstr ;
  111. //jeXForm3d_SetMaximalAssertionMode( JE_FALSE ) ;
  112. CString ObjectDllPath;
  113. char Path[MAX_PATH];
  114. jeMemAllocInfo_Create("Preferences.jMAI");
  115. //...
  116. }
  117. int CJweApp::ExitInstance()
  118. {
  119. //...
  120. jeMemAllocInfo_Destroy();
  121. return CWinApp::ExitInstance();
  122. }// ExitInstance
  123. //...
  124. // >Editor-MFC Files-Doc.cpp<
  125. // ...
  126. #include "jeMemAllocInfo.h"
  127. //...
  128. CJweDoc::CJweDoc() : m_pLevel(NULL), m_Mode(MODE_POINTER_BB), m_LastFOV( 2.0f ), m_bLoaded( JE_FALSE ), m_Anim_State(0)
  129. {
  130. // TODO: add one-time construction code here
  131. jeMemAllocInfo_Activate();
  132. //...
  133. }
  134. CJweDoc::~CJweDoc()
  135. {
  136. //...
  137. jeMemAllocInfo_DeActivate(JE_TRUE);
  138. AfxOleUnlockApp();
  139. }
  140. //...
  141. // Usage sample end
  142. #endif