home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cslio205.zip / INCLUDE / CSMALLOC.H < prev    next >
C/C++ Source or Header  |  1997-01-21  |  3KB  |  120 lines

  1. /***********************************************************************
  2.  
  3.                        CSA Library, Free Evaluation Version 2.0.5 
  4.                                        Release: January 22th 1997 
  5.  
  6.        Preprocessor commands to replace all memory
  7.        allocation functions with new ones to log
  8.        and check the use of the heap.
  9.  
  10.        It also contains the QA class.
  11.  
  12.  
  13.                                            Copyright(c) 1994-1997 
  14.                                                           ComBits 
  15.                                                   The Netherlands 
  16. ***********************************************************************/
  17.  
  18. #ifndef __CSMALLOC_H
  19. #define __CSMALLOC_H
  20.  
  21.  
  22. #ifdef _CP_001
  23.   #include "alloc.h"
  24. #endif
  25.  
  26. #include "malloc.h"
  27. #include "stdlib.h"
  28. #include "cstypes.h"
  29.  
  30.  
  31. ////////////////////////////////////////////////////////////////////////////////
  32. //       ......................... QA ............................
  33. //
  34. //       Quick Allocation.
  35. //       A class to do dynamic memory allocations.
  36. //
  37. //
  38.  
  39.  
  40. class QA
  41. {
  42.  public:
  43.    void *p;
  44.  
  45.  public:
  46.  
  47.    QA(unsigned int n);
  48.   ~QA(void);
  49.  
  50.    void free(void);
  51.  
  52. #ifndef _CP_002
  53.    operator void*()      { return p; }
  54. #endif
  55.    operator csCHAR*()    { return (csCHAR *)p; }
  56.  
  57.  
  58. };
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. #if defined(CS_DEBUG)
  66.  
  67. // Special allocation functions during debugging.
  68.  
  69.   #define  csmalloc(x)       cs_malloc(x,      __FILE__,__LINE__)
  70.   #define  cscalloc(x,y)     cs_calloc(x,y,    __FILE__,__LINE__)
  71.   #define  csrealloc(x,y)    cs_realloc(x,y,   __FILE__,__LINE__)
  72.   #define  csfree(x)         cs_free(x,        __FILE__,__LINE__)
  73. #ifndef _CP_100
  74.   #define  csfarmalloc(x)    cs_farmalloc(x,   __FILE__,__LINE__)
  75.   #define  csfarcalloc(x,y)  cs_farcalloc(x,y, __FILE__,__LINE__)
  76.   #define  csfarrealloc(x,y) cs_farrealloc(x,y,__FILE__,__LINE__)
  77.   #define  csfarfree(x)      cs_farfree(x,     __FILE__,__LINE__)
  78. #endif
  79.  
  80. #else
  81.   #define  csmalloc(x)        ::malloc(x)
  82.   #define  cscalloc(x,y)      ::calloc(x,y)
  83.   #define  csrealloc(x,y)     ::realloc(x,y)
  84.   #define  csfree(x)          ::free(x)
  85. #ifndef _CP_100
  86.   #define  csfarmalloc(x)     ::farmalloc(x)
  87.   #define  csfarcalloc(x,y)   ::farcalloc(x,y)
  88.   #define  csfarrealloc(x,y)  ::farrealloc(x,y)
  89.   #define  csfarfree(x)       ::farfree(x)
  90. #endif
  91.  
  92. #endif
  93.  
  94.  
  95. void   alloc_test(csCHAR *fname,long line);
  96.  
  97. void   alloc_logging(int TrueFalse,csCHAR *name);
  98. inline void  alloc_logging(int TrueFalse)
  99.        { alloc_logging(TrueFalse,(csCHAR *)"malloc.log"); }
  100.  
  101.  
  102. void  *  cs_realloc(void  *ptr, size_t __size,csCHAR *fname,long line);
  103. void  *  cs_calloc(size_t __nitems, size_t __size,csCHAR *fname,long line);
  104. void     cs_free(void *__block,csCHAR *fname,long line);
  105. void  *  cs_malloc(size_t __size,csCHAR *fname,long line);
  106.  
  107.  
  108. #ifndef _CP_100
  109. // No 'far-version' with the flat memory model.
  110.  
  111. void far  * cs_farcalloc(unsigned long __nunits, unsigned long __unitsz,csCHAR *fname,long line);
  112. void far  * cs_farrealloc(void far * ptr,unsigned long __nunits,csCHAR *fname,long line);
  113. void        cs_farfree(void far *__block,csCHAR *fname,long line);
  114. void far  * cs_farmalloc(unsigned long __nbytes,csCHAR *fname,long line);
  115.  
  116. #endif
  117.  
  118.  
  119. #endif
  120.