home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6574.LZX / include / memwatch.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-04  |  4.0 KB  |  98 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  2. * |_o_o|\\ Copyright (c) 1989 The Software Distillery.                    *
  3. * |. o.| ||          All Rights Reserved                                  *
  4. * | .  | ||          Written by Doug Walker                               *
  5. * | o  | ||          The Software Distillery                              *
  6. * |  . |//           235 Trillingham Lane                                 *
  7. * ======             Cary, NC 27513                                       *
  8. *                    BBS:(919)-471-6436                                   *
  9. \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  10.  
  11. #ifndef D_MEMWATCH_H
  12. #define D_MEMWATCH_H
  13.  
  14. #include <exec/types.h>
  15.  
  16. /* The following files are included so you won't get an error if */
  17. /* you include them AFTER this file.                             */
  18. #include <stdlib.h>   /* Get prototype for malloc() */
  19. #include <dos.h>      /* Get prototype for getcwd() and getenv() */
  20. #include <string.h>   /* Get prototype for strdup() */
  21.  
  22. /* Flags for MWInit */
  23. #define MWF_NOCHECK   0x00000000 /* (compatibility - do not use)         */
  24. #define MWF_NOLOG     0x00000002 /* No debug messages                    */
  25. #define MWF_CHECK     0x00000004 /* Check mem whenever mem rtns called   */
  26. #define MWF_NOFREE    0x00000008 /* Don't free nonfreed memory           */
  27. #define MWF_NOFTRASH  0x00000010 /* Don't trash memory upon free         */
  28. #define MWF_NOATRASH  0x00000020 /* Don't trash memory upon alloc        */
  29. #define MWF_NOFKEEP   0x00000040 /* Don't keep memory after free         */
  30. #define MWF_MALLOCWRN 0x00000080 /* Warn about malloc'd mem not freed    */
  31. #define MWF_SERIAL    0x00000100 /* Use serial port for output           */
  32.  
  33. #define MWF_ACTIVE   0x80000000 /* PRIVATE - MemWatch is active          */
  34. #define MWF_ERROR    0x40000000 /* PRIVATE - Error discovered, terminate */
  35.  
  36. /* PRIVATE. Flags for the INTERNAL argument to MWAllocMem. */
  37. #define MWI_MALLOC   0x00000001  // Memory allocated with malloc
  38. #define MWI_VEC      0x00000002  // Memory allocated with AllocVec
  39. #define MWI_ANY      (MWI_MALLOC|MWI_VEC)
  40.  
  41. /* Flags to tell MWReport how much to report */
  42. #define MWR_NONE 0   /* Don't report anything; just return    */
  43. #define MWR_SUM  1   /* Report current and total usage        */
  44. #define MWR_FULL 2   /* Report on all outstanding allocations */
  45.  
  46. #if MWDEBUG
  47.  
  48. #ifdef free
  49. #undef free
  50. #endif
  51.  
  52. #define AllocMem(size,flags) MWAllocMem(size, flags, 0, __FILE__, __LINE__)
  53. #define FreeMem(mem,size)    MWFreeMem(mem, size, 0, __FILE__, __LINE__)
  54. #define AllocVec(size,flags) MWAllocMem(size, flags, MWI_VEC, __FILE__, __LINE__)
  55. #define FreeVec(mem)         MWFreeMem(mem, -1, MWI_VEC, __FILE__, __LINE__)
  56. #define malloc(size)         MWAllocMem(size, 0, MWI_MALLOC, __FILE__, __LINE__)
  57. #define halloc(size)         malloc(size)
  58. #define calloc(nelt,esize)   MWAllocMem((nelt)*(esize), MEMF_CLEAR, \
  59.                                         MWI_MALLOC, __FILE__, __LINE__)
  60. #define realloc(mem,size)    MWrealloc(mem,size,__FILE__,__LINE__)
  61. #define free(mem)            MWFreeMem(mem, -1, MWI_MALLOC, __FILE__, __LINE__)
  62.  
  63. #define strdup(str)          MWStrDup(str, __FILE__, __LINE__)
  64. #define getcwd(b,size)       MWGetCWD(b,size,__FILE__,__LINE__)
  65. #ifdef getenv
  66. #undef getenv
  67. #endif
  68. #define getenv(name)         MWGetEnv(name, __FILE__, __LINE__)
  69.  
  70. void MWInit      (LONG, LONG, char *);
  71. void MWTerm      (void);
  72. void *MWAllocMem (long, long, long, char *, long);
  73. void MWFreeMem   (void *, long, long, char *, long);
  74. void MWCheck     (void);
  75. void MWReport    (char *, long);
  76. void MWLimit     (LONG, LONG);
  77. void *MWrealloc  (void *, long, char *, long);
  78.  
  79. char *MWStrDup   (const char *, char *, long);
  80. char *MWGetEnv   (const char *, char *, long);
  81. char *MWGetCWD   (char *, int, char *, long);
  82.  
  83. extern unsigned long  __MWFlags;
  84. extern char *__MWLogName;
  85.  
  86. #else /* MWDEBUG */
  87.  
  88. /* No memory debugging - make everything go away */
  89.  
  90. #define MWInit(a,b,c)
  91. #define MWTerm()
  92. #define MWCheck()
  93. #define MWReport(a,b)
  94. #define MWLimit(a,b)
  95.  
  96. #endif /* MWDEBUG */
  97. #endif /* D_MEMWATCH_H */
  98.