home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / bit_blt / amiga / mem.c < prev    next >
C/C++ Source or Header  |  1987-04-24  |  760b  |  40 lines

  1. /*
  2.  *   Memory allocation and deallocation for BlitLab.
  3.  */
  4. #include "structures.h"
  5. struct memnode {
  6.    struct memnode * next ;
  7.    long size ;
  8. } ;
  9. static struct memnode *head ;
  10. /*
  11.  *   Replacement for AllocMem.  If not enough memory, we exit.
  12.  */
  13. void *allocmem(size, type)
  14. long size ;
  15. long type ;
  16. {
  17.    struct memnode *p ;
  18.    extern void *AllocMem() ;
  19.  
  20.    p = (struct memnode *)AllocMem(size + sizeof(struct memnode), type) ;
  21.    if (p==NULL)
  22.       error("! out of memory") ;
  23.    p->size = size + sizeof(struct memnode) ;
  24.    p->next = head ;
  25.    head = p ;
  26.    return(p + 1) ;
  27. }
  28. /*
  29.  *   Frees all allocated memory.
  30.  */
  31. freemem() {
  32.    struct memnode *p ;
  33.  
  34.    while (head != NULL) {
  35.       p = head->next ;
  36.       FreeMem(head, head->size) ;
  37.       head = p ;
  38.    }
  39. }
  40.