home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / base / memory.h < prev    next >
C/C++ Source or Header  |  1995-04-08  |  2KB  |  96 lines

  1.  
  2.  
  3.  
  4.  
  5. #ifndef _memory_h_ /* Sat Aug 27 13:59:50 1994 */
  6. #define _memory_h_
  7.  
  8.  
  9.  
  10.  
  11. /*
  12.  *
  13.  *          Copyright (C) 1994, M. A. Sridhar
  14.  *  
  15.  *
  16.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  17.  *     to copy, modify or distribute this software  as you see fit,
  18.  *     and to use  it  for  any  purpose, provided   this copyright
  19.  *     notice and the following   disclaimer are included  with all
  20.  *     copies.
  21.  *
  22.  *                        DISCLAIMER
  23.  *
  24.  *     The author makes no warranties, either expressed or implied,
  25.  *     with respect  to  this  software, its  quality, performance,
  26.  *     merchantability, or fitness for any particular purpose. This
  27.  *     software is distributed  AS IS.  The  user of this  software
  28.  *     assumes all risks  as to its quality  and performance. In no
  29.  *     event shall the author be liable for any direct, indirect or
  30.  *     consequential damages, even if the  author has been  advised
  31.  *     as to the possibility of such damages.
  32.  *
  33.  */
  34.  
  35.  
  36.  
  37.  
  38. #ifdef __GNUC__
  39. #pragma interface
  40. #endif
  41.  
  42.  
  43. #include <stddef.h>
  44. #include "base/defs.h"
  45.  
  46.  
  47.  
  48. // Create an instance of MemoryLeakChecker in any scope in which leaks must
  49. // be checked. When this object is destroyed, it prints a record of all
  50. // currently  allocated blocks onto the stream. For example, in the code:
  51. //
  52. // \begin{verbatim}
  53. //      #include <iostream.h>
  54. //      main ()
  55. //      {
  56. //          CL_MemoryLeakChecker chk (cout);
  57. //          ...
  58. //      }
  59. // \end{verbatim}
  60. //
  61. // all blocks still allocated at the end of the main program are printed on
  62. // {\tt cout}.
  63.  
  64. class __FAR ostream;
  65.  
  66. class CL_EXPORT CL_MemoryLeakChecker {
  67. public:
  68.     CL_MemoryLeakChecker (ostream& stream);
  69.     ~CL_MemoryLeakChecker ();
  70.  
  71.     static long CurrentMemoryUsage ();
  72.     // Return the amount of memory currently allocated.
  73.     
  74.     static long MaxMemoryUsed ();
  75.     // Return the maximum amount of memory used so far by this application.
  76.     
  77. protected:
  78.     ostream& _stream;
  79.     
  80. };
  81.  
  82. void* operator new (size_t size, short line_no, const char*
  83.                     file_name);
  84.  
  85. #if defined(__GNUC__) && __GNUC_MINOR__ >= 6
  86. void* operator new[] (size_t size, short line_no, const char* file_name);
  87. #endif
  88.  
  89. #if defined(__BORLANDC__) && __BCPLUSPLUS__ >= 0x0330
  90. void* operator new[] (size_t size, short line_no, const char* file_name);
  91. #endif
  92.  
  93. #define new new(__LINE__, __FILE__)
  94.  
  95. #endif /* _memory_h_ */
  96.