home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / exec / createpool.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  2.5 KB  |  110 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: createpool.c,v 1.9 1997/01/07 12:32:02 digulla Exp $
  4.  
  5.     Desc:
  6.     Lang:
  7. */
  8. #include "exec_intern.h"
  9. #include <aros/libcall.h>
  10. #include <clib/alib_protos.h>
  11. #include <aros/machine.h>
  12. #include "memory.h"
  13. #include <exec/memory.h>
  14. #include <proto/exec.h>
  15.  
  16. #define NEWLIST(l) \
  17. ((l)->lh_Head=(struct Node *)&(l)->lh_Tail, \
  18.  (l)->lh_Tail=NULL,                         \
  19.  (l)->lh_TailPred=(struct Node *)(l))
  20.  
  21. /*****************************************************************************
  22.  
  23.     NAME */
  24.  
  25.     AROS_LH3(APTR, CreatePool,
  26.  
  27. /*  SYNOPSIS */
  28.     AROS_LHA(ULONG, requirements, D0),
  29.     AROS_LHA(ULONG, puddleSize,   D1),
  30.     AROS_LHA(ULONG, threshSize,   D2),
  31.  
  32. /*  LOCATION */
  33.     struct ExecBase *, SysBase, 116, Exec)
  34.  
  35. /*  FUNCTION
  36.     Create a private pool for memory allocations.
  37.  
  38.     INPUTS
  39.     requirements - The type of the memory
  40.     puddleSize   - The number of bytes that the pool expands
  41.                if it is too small.
  42.     threshSize   - Allocations beyond the threshSize are given
  43.                directly to the system. threshSize must be
  44.                smaller than the puddleSize.
  45.  
  46.     RESULT
  47.     A handle for the memory pool or NULL if the pool couldn't
  48.     be created
  49.  
  50.     NOTES
  51.  
  52.     EXAMPLE
  53.     \* Get the handle to a private memory pool *\
  54.     po=CreatePool(MEMF_ANY,16384,8192);
  55.     if(po!=NULL)
  56.     {
  57.         \* Use the pool *\
  58.         UBYTE *mem1,*mem2;
  59.         mem1=AllocPooled(po,1000);
  60.         mem2=AllocPooled(po,2000);
  61.         \* Do something with the memory... *\
  62.  
  63.         \* Free everything at once *\
  64.         DeletePool(po);
  65.     }
  66.  
  67.     BUGS
  68.  
  69.     SEE ALSO
  70.     DeletePool(), AllocPooled(), FreePooled()
  71.  
  72.     INTERNALS
  73.  
  74.     HISTORY
  75.     16-10-95    created by m. fleischer
  76.  
  77. ******************************************************************************/
  78. {
  79.     AROS_LIBFUNC_INIT
  80.  
  81.     struct Pool *pool=NULL;
  82.  
  83.     /* puddleSize must not be smaller than threshSize */
  84.     if(puddleSize>=threshSize)
  85.     {
  86.     /* Round puddleSize up to be a multiple of MEMCHUNK_TOTAL. */
  87.     puddleSize=(puddleSize+MEMCHUNK_TOTAL-1)&~(MEMCHUNK_TOTAL-1);
  88.  
  89.     /*
  90.         Allocate memory for the Pool structure using the same requirements
  91.         as for the whole pool (to make it shareable, residentable or
  92.         whatever is needed).
  93.     */
  94.     pool=(struct Pool *)AllocMem(sizeof(struct Pool),requirements);
  95.     if(pool!=NULL)
  96.     {
  97.         /* Clear the lists */
  98.         NEWLIST((struct List *)&pool->PuddleList);
  99.         NEWLIST((struct List *)&pool->BlockList );
  100.  
  101.         /* Set the rest */
  102.         pool->Requirements=requirements;
  103.         pool->PuddleSize  =puddleSize;
  104.         pool->ThreshSize  =threshSize;
  105.     }
  106.     }
  107.     return pool;
  108.     AROS_LIBFUNC_EXIT
  109. } /* CreatePool */
  110.