home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga Shareware Floppies / ma58.dms / ma58.adf / superplay-lib_DEV / Programmers / Example_SPObjects / SPO / SP_MemSubs.c < prev    next >
C/C++ Source or Header  |  1996-05-27  |  2KB  |  90 lines

  1.  
  2.  /* SP_MemSubs.c
  3.     - Memory Management Routines for SPObject-Support -
  4.     (c) 1990-94 by Andreas R. Kleinert
  5.     Last changes : 25.02.1994
  6.  */
  7.  
  8. #include "spobject.h"
  9.  
  10.  /* Memory-Support-Functions */
  11.  
  12. struct AIM_MemList * __saveds __stdargs AIM_GetMemList(void);
  13. void                 __saveds __stdargs AIM_FreeMemList(struct AIM_MemList *MemList);
  14. long             __saveds __stdargs AIM_AddMemEntry(struct AIM_MemList *mlist, APTR pointer, long size);
  15. APTR             __saveds __stdargs AIM_AllocMemEntry(struct AIM_MemList *mlist, ULONG size, ULONG type);
  16.  
  17.  
  18. struct AIM_MemList * __saveds __stdargs AIM_GetMemList(void)
  19. {
  20.  struct AIM_MemList  *MemList = N;
  21.  struct List        *samelist = N;
  22.  
  23.  samelist = (struct List *) AllocVec(sizeof(struct AIM_MemList), MEMF_CLEAR);
  24.  if(samelist)
  25.   {
  26.    MemList = (APTR) samelist;
  27.  
  28.    MemList->ml_NumEntries = 0;
  29.  
  30.    samelist->lh_Head     = (struct Node *) &(samelist->lh_Tail);
  31.    samelist->lh_Tail     = N;
  32.    samelist->lh_TailPred = (struct Node *) &(samelist->lh_Head);
  33.    samelist->lh_Type     = NT_UNKNOWN;
  34.   }else return(NULL);
  35.  
  36.  return(MemList);
  37. }
  38.  
  39. void __saveds __stdargs AIM_FreeMemList(struct AIM_MemList *MemList)
  40. {
  41.  struct AIM_MemEntry *entry;
  42.  
  43.  if(MemList)
  44.   {
  45.    for(entry=(APTR) MemList->ml_EntryList.lh_Head;(entry)&&(entry!=(APTR) &(MemList->ml_EntryList.lh_Tail));)
  46.     {
  47.      Remove((APTR) entry);
  48.      FreeVec(entry->MemPointer);
  49.      FreeVec(entry);
  50.      entry = (APTR) MemList->ml_EntryList.lh_Head;
  51.     }
  52.  
  53.    FreeVec(MemList);
  54.   }
  55. }
  56.  
  57. long __saveds __stdargs AIM_AddMemEntry(struct AIM_MemList *mlist, APTR pointer, long size)
  58. {
  59.  struct AIM_MemEntry *entry;
  60.  
  61.  if(!mlist || !pointer || !size) return(FALSE);
  62.  
  63.  entry = (APTR) AllocVec(sizeof(struct AIM_MemEntry), (MEMF_CLEAR|MEMF_PUBLIC));
  64.  if(!entry)
  65.   {
  66.    FreeVec(pointer);
  67.    return(FALSE);
  68.   }
  69.  
  70.  mlist->ml_NumEntries++;
  71.  
  72.  entry->MemPointer = pointer;
  73.  
  74.  AddHead((APTR)mlist, (APTR)entry);
  75.  
  76.  return(TRUE);
  77. }
  78.  
  79. APTR __saveds __stdargs AIM_AllocMemEntry(struct AIM_MemList *mlist, ULONG size, ULONG type)
  80. {
  81.  APTR alloc;
  82.  
  83.  alloc = AllocVec(size, type);
  84.  if(!alloc) return(N);
  85.  
  86.  if(!AIM_AddMemEntry(mlist, alloc, size)) return(N);
  87.  
  88.  return(alloc);
  89. }
  90.