home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 3 / RISC_DISC_3.iso / resources / etexts / gems / gemsv / ch3_5 / bspmemory.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  745 b   |  33 lines

  1. /* bspMemory.c: module to allocate and free memory and also to count them.
  2.  * Copyright (c) Norman Chin 
  3.  */
  4. #include "bsp.h"        
  5. #include <malloc.h>
  6.  
  7. static long memoryCount= 0L;
  8.  
  9. /* Allocates memory of num bytes */
  10. char *MYMALLOC(unsigned num)
  11. {
  12.    char *memory= malloc(num);    /* checked for null by caller */
  13.  
  14.    ++memoryCount;        /* increment memory counter for debugging */
  15.    return(memory);
  16. } /* myMalloc() */
  17.  
  18. /* Frees memory pointed to by ptr */
  19. void MYFREE(char *ptr) 
  20. {
  21.    --memoryCount;        /* decrement memory counter for debugging */
  22.    free(ptr);
  23. } /* myFree() */
  24.  
  25. /* Returns how many memory blocks are still allocated up to this point */
  26. long MYMEMORYCOUNT(void)
  27. {
  28.    return(memoryCount);
  29. } /* myMemoryCount() */
  30.  
  31. /*** bspMemory.c ***/
  32.  
  33.