home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / memory / src / createpool.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  2.6 KB  |  107 lines

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