home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ctdemo.zip / classes / @CLSLIB1.ZIP / cls / runtime / test / heap_t2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.5 KB  |  151 lines

  1. #ifndef INCL_HEAP_T2
  2. #define INCL_HEAP_T2
  3.  
  4. #ifndef __FIRST__
  5. #define __FIRST__
  6. #define __IMPL__HEAP_T2
  7. #endif
  8.  
  9. /////V Heap_t2 PCM f:\cls_ibm\cls\runtime\test 0 PM 18.12.94 01:57:50
  10.  
  11. /*
  12. /////H 
  13. 18.12.94 01:57 PM 0 copied from: Heap_t2 TOS f:\cls_ibm\cls\runtime\test 0 PM 19.10.94 00:46:26
  14. 30.03.95 10:34 PM 0 archived: Heap_t2 PCM f:\cls_ibm\cls\runtime\test 0 PM 18.12.94 01:57:50
  15. /////
  16. */
  17.  
  18. /////1
  19. #undef inline
  20.  
  21. #include <bsa.h>
  22.  
  23. /////I Heap @ @ @ @ pre class 
  24. #include <Heap.cpp>
  25.  
  26. /////I stdio.h @ @ @ @ pre 
  27. #include <stdio.h>
  28.  
  29. /////T auxTypes pre 
  30. class Z {
  31.     int d;
  32. };
  33.  
  34. class Y {
  35.     int d;
  36.     Z*    pZ;
  37.   public:
  38.     Y () { pZ = NEW( Z, () ); }
  39.     ~Y () { DELETE( pZ); }
  40. };
  41.  
  42. class X {
  43.     int d;
  44.     Y*  pY;
  45.   public:
  46.     X () { pY = NEW( Y, () ); }
  47.     ~X () { DELETE( pY); }
  48. };
  49. /////
  50.  
  51.  
  52. #ifndef __INLINE__
  53. #define inline
  54. #endif
  55.  
  56. /////C Heap_t2 @ @ use:__HEAPTRACE__ usesDefine define:_VIO_ app test 
  57. class Heap_t2
  58.  
  59. {
  60.  
  61. protected:
  62. /////D Data @  @ instance protected 
  63.     int     Data;
  64.  
  65.  
  66. public:
  67.     static int    doThat ();
  68.     static int    doThis ();
  69. };
  70.  
  71.     int    main (int,char*[]);
  72.  
  73. /////2
  74. #undef inline
  75.  
  76.  
  77. #if (defined __INLINE__) || (defined __IMPL__HEAP_T2)
  78.  
  79. #ifndef __INLINE__
  80. #define inline
  81. #endif
  82.  
  83. /////
  84. #endif
  85.  
  86. /////3
  87. #undef inline
  88.  
  89. #ifdef __IMPL__HEAP_T2
  90. /////F doThat @ @ class public 
  91. int Heap_t2:: doThat ()
  92. {
  93.     puts( "doThat()");
  94.  
  95.     char*c = NEW_STR( "aString") ;        // dup a string
  96.     DELETE_STR( c);                        // and free again
  97.  
  98.     return 1;
  99. }
  100.  
  101. /////F doThis @ @ class public 
  102. int Heap_t2:: doThis ()
  103. {
  104.     puts( "doThis()");
  105.  
  106.     char*c = NEW_VEC( char, 12);    // vector alloc
  107.     DELETE_VEC( c);                    // vector free
  108.  
  109.     return 1;
  110. }
  111.  
  112. /////F main @ @ use:__HEAPTRACE__ global usesDefine 
  113. int main ( int argc, char* argv[] )
  114. {
  115.     /*
  116.         *** CThrough heaptrace demo app ***
  117.         to trace heap operations use ExeBuilder's
  118.         heaptrace switch. The heaptrace.hlg file may be analyzed
  119.         by BsaController's tool 'HeapTracer'.
  120.     */
  121.  
  122.     int i;
  123.  
  124. #ifndef __HEAPTRACE__
  125.     printf( "heaptrace off !\nbuild with heaptrace switch to trace operations\n\n");
  126. #endif
  127.  
  128.     printf( "*** now entering main() of Heap_t2\n");
  129.  
  130.     for ( i=0; i < 5; i++ ) {
  131.         Heap_t2::doThis();
  132.         Heap_t2::doThat();
  133.  
  134.         char *p = NEW_VEC( char, 100);    // this is a memory leak demo
  135.  
  136.         X* pX = NEW( X, () );        
  137.         DELETE( pX);
  138.     }
  139.  
  140. #ifdef __HEAPTRACE__
  141.     printf( "\ntraced operations may be analyzed by ExeBuilder's <Show><Heaptrace> now");
  142. #endif
  143.  
  144.     return 0;
  145. }
  146.  
  147. /////
  148. #endif
  149.  
  150. #endif
  151.