memory.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: memory.h
  3. // Purpose: interface of wxDebugContext
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxDebugContext
  9. A class for performing various debugging and memory tracing operations.
  10. Full functionality (such as printing out objects currently allocated) is
  11. only present in a debugging build of wxWidgets, i.e. if the __WXDEBUG__
  12. symbol is defined. wxDebugContext and related functions and macros can be
  13. compiled out by setting wxUSE_DEBUG_CONTEXT to 0 is setup.h
  14. @library{wxbase}
  15. @category{debugging}
  16. @see @ref overview_debugging
  17. */
  18. class wxDebugContext
  19. {
  20. public:
  21. /**
  22. Checks the memory blocks for errors, starting from the currently set
  23. checkpoint.
  24. @return Returns the number of errors, so a value of zero represents
  25. success. Returns -1 if an error was detected that prevents
  26. further checking.
  27. */
  28. static int Check(bool checkAll = false);
  29. /**
  30. Performs a memory dump from the currently set checkpoint, writing to the
  31. current debug stream. Calls the @b Dump member function for each wxObject
  32. derived instance.
  33. @return @true if the function succeeded, @false otherwise.
  34. */
  35. static bool Dump();
  36. /**
  37. Returns @true if the memory allocator checks all previous memory blocks for
  38. errors.
  39. By default, this is @false since it slows down execution considerably.
  40. @see SetCheckPrevious()
  41. */
  42. static bool GetCheckPrevious();
  43. /**
  44. Returns @true if debug mode is on.
  45. If debug mode is on, the wxObject new and delete operators store or use
  46. information about memory allocation. Otherwise, a straight malloc and
  47. free will be performed by these operators.
  48. @see SetDebugMode()
  49. */
  50. static bool GetDebugMode();
  51. /**
  52. Gets the debug level (default 1).
  53. The debug level is used by the wxTraceLevel function and the WXTRACELEVEL
  54. macro to specify how detailed the trace information is; setting a
  55. different level will only have an effect if trace statements in the
  56. application specify a value other than one.
  57. @deprecated
  58. This is obsolete, replaced by wxLog functionality.
  59. @see SetLevel()
  60. */
  61. static int GetLevel();
  62. /**
  63. Prints a list of the classes declared in this application, giving derivation
  64. and whether instances of this class can be dynamically created.
  65. @see PrintStatistics()
  66. */
  67. static bool PrintClasses();
  68. /**
  69. Performs a statistics analysis from the currently set checkpoint, writing
  70. to the current debug stream. The number of object and non-object
  71. allocations is printed, together with the total size.
  72. @param detailed
  73. If @true, the function will also print how many objects of each class
  74. have been allocated, and the space taken by these class instances.
  75. @see PrintStatistics()
  76. */
  77. static bool PrintStatistics(bool detailed = true);
  78. /**
  79. Tells the memory allocator to check all previous memory blocks for errors.
  80. By default, this is @false since it slows down execution considerably.
  81. @see GetCheckPrevious()
  82. */
  83. static void SetCheckPrevious(bool check);
  84. /**
  85. Sets the current checkpoint: Dump and PrintStatistics operations will
  86. be performed from this point on. This allows you to ignore allocations
  87. that have been performed up to this point.
  88. @param all
  89. If @true, the checkpoint is reset to include all memory allocations
  90. since the program started.
  91. */
  92. static void SetCheckpoint(bool all = false);
  93. /**
  94. Sets the debug mode on or off.
  95. If debug mode is on, the wxObject new and delete operators store or use
  96. information about memory allocation. Otherwise, a straight malloc and free
  97. will be performed by these operators.
  98. By default, debug mode is on if __WXDEBUG__ is defined. If the application
  99. uses this function, it should make sure that all object memory allocated
  100. is deallocated with the same value of debug mode. Otherwise, the delete
  101. operator might try to look for memory information that does not exist.
  102. @see GetDebugMode()
  103. */
  104. static void SetDebugMode(bool debug);
  105. /**
  106. Sets the debug level (default 1).
  107. The debug level is used by the wxTraceLevel function and the WXTRACELEVEL
  108. macro to specify how detailed the trace information is; setting
  109. a different level will only have an effect if trace statements in the
  110. application specify a value other than one.
  111. @deprecated
  112. This is obsolete, replaced by wxLog functionality.
  113. @see GetLevel()
  114. */
  115. static void SetLevel(int level);
  116. /**
  117. Installs a function to be called at the end of wxWidgets shutdown.
  118. It will be called after all files with global instances of
  119. wxDebugContextDumpDelayCounter have run their destructors.
  120. The shutdown function must be take no parameters and return nothing.
  121. */
  122. static void SetShutdownNotifyFunction(wxShutdownNotifyFunction func);
  123. };
  124. // ============================================================================
  125. // Global functions/macros
  126. // ============================================================================
  127. /** @addtogroup group_funcmacro_log */
  128. //@{
  129. /**
  130. @deprecated Use one of the wxLogTrace() functions or one of the
  131. wxVLogTrace() functions instead.
  132. Calls wxTrace() with printf-style variable argument syntax. Output is
  133. directed to the current output stream (see wxDebugContext).
  134. @header{wx/memory.h}
  135. */
  136. #define WXTRACE(format, ...)
  137. /**
  138. @deprecated Use one of the wxLogTrace() functions or one of the
  139. wxVLogTrace() functions instead.
  140. Calls wxTraceLevel with printf-style variable argument syntax. Output is
  141. directed to the current output stream (see wxDebugContext). The first
  142. argument should be the level at which this information is appropriate. It
  143. will only be output if the level returned by wxDebugContext::GetLevel is
  144. equal to or greater than this value.
  145. @header{wx/memory.h}
  146. */
  147. #define WXTRACELEVEL(level, format, ...)
  148. /**
  149. @deprecated Use one of the wxLogTrace() functions or one of the
  150. wxVLogTrace() functions instead.
  151. Takes printf-style variable argument syntax. Output is directed to the
  152. current output stream (see wxDebugContext).
  153. @header{wx/memory.h}
  154. */
  155. void wxTrace(const wxString& format, ...);
  156. /**
  157. @deprecated Use one of the wxLogTrace() functions or one of the
  158. wxVLogTrace() functions instead.
  159. Takes @e printf() style variable argument syntax. Output is directed to the
  160. current output stream (see wxDebugContext). The first argument should be
  161. the level at which this information is appropriate. It will only be output
  162. if the level returned by wxDebugContext::GetLevel() is equal to or greater
  163. than this value.
  164. @header{wx/memory.h}
  165. */
  166. void wxTraceLevel(int level, const wxString& format, ...);
  167. //@}