home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR9 / HEAP20.ZIP / HTEST.C < prev   
C/C++ Source or Header  |  1993-10-05  |  2KB  |  81 lines

  1. #include <alloc.h>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include "heap.h"
  5.  
  6. void main(void)
  7. {
  8.   char  far *ptr1,
  9.         far *ptr2,
  10.         far *ptr3;
  11.   unsigned int  handle1,
  12.                 handle2,
  13.                 handle3;
  14.  
  15.   clrscr();
  16.   printf("Without the Heap Library.\n\n");
  17.   printf("Free memory = %ld\n", farcoreleft());
  18.  
  19.   printf("Allocating 10000 bytes.\n");
  20.   ptr1 = farmalloc(10000);
  21.  
  22.   printf("Allocating 50000 bytes.\n");
  23.   ptr2 = farmalloc(50000);
  24.  
  25.   printf("Allocating 20000 bytes.\n");
  26.   ptr3 = farmalloc(20000);
  27.  
  28.   printf("Free memory = %ld\n\n", farcoreleft());
  29.  
  30.   printf("Releasing second allocation.\n");
  31.   farfree(ptr2);
  32.   printf("Free memory = %ld\n\n", farcoreleft());
  33.  
  34.   printf("Releasing first allocation.\n");
  35.   farfree(ptr1);
  36.   printf("Free memory = %ld\n\n", farcoreleft());
  37.  
  38.   printf("Releasing third allocation.\n");
  39.   farfree(ptr3);
  40.   printf("Free memory = %ld\n\n", farcoreleft());
  41.  
  42.   printf("Press a key..");
  43.   getch();
  44.  
  45.  
  46.   clrscr();
  47.   printf("With the Heap Library V%s\n\n", HeapVersion);
  48.   if (!InitHeap(3, 90000)) {
  49.     printf("Error initializing heap: #%d\n", HeapError);
  50.     printf("Not enough memory for this demonstration.\n");
  51.     return;
  52.    }
  53.  
  54.   printf("Free memory = %ld\n", HeapUnused);
  55.  
  56.   printf("Allocating 10000 bytes.\n");
  57.   handle1 = Halloc(10000);
  58.  
  59.   printf("Allocating 50000 bytes.\n");
  60.   handle2 = Halloc(50000);
  61.  
  62.   printf("Allocating 20000 bytes.\n");
  63.   handle3 = Halloc(20000);
  64.  
  65.   printf("Free memory = %ld\n\n", HeapUnused);
  66.  
  67.   printf("Releasing second allocation.\n");
  68.   Hfree(handle2);
  69.   printf("Free memory = %ld\n\n", HeapUnused);
  70.  
  71.   printf("Releasing first allocation.\n");
  72.   Hfree(handle1);
  73.   printf("Free memory = %ld\n\n", HeapUnused);
  74.  
  75.   printf("Releasing third allocation.\n");
  76.   Hfree(handle3);
  77.   printf("Free memory = %ld\n\n", HeapUnused);
  78.  
  79.   UnInitHeap();
  80. }
  81.