2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Create a memory pool.
8 #include "exec_intern.h"
9 #include <aros/libcall.h>
10 #include <clib/alib_protos.h>
13 /*****************************************************************************
16 #include <exec/memory.h>
17 #include <proto/exec.h>
19 AROS_LH3(APTR
, CreatePool
,
22 AROS_LHA(ULONG
, requirements
, D0
),
23 AROS_LHA(ULONG
, puddleSize
, D1
),
24 AROS_LHA(ULONG
, threshSize
, D2
),
27 struct ExecBase
*, SysBase
, 116, Exec
)
30 Create a private pool for memory allocations.
33 requirements - The type of the memory
34 puddleSize - The number of bytes that the pool expands
36 threshSize - Allocations beyond the threshSize are given
37 directly to the system. threshSize must be
38 smaller or equal than the puddleSize.
41 A handle for the memory pool or NULL if the pool couldn't
47 \* Get the handle to a private memory pool *\
48 po=CreatePool(MEMF_ANY,16384,8192);
53 mem1=AllocPooled(po,1000);
54 mem2=AllocPooled(po,2000);
55 \* Do something with the memory... *\
57 \* Free everything at once *\
64 DeletePool(), AllocPooled(), FreePooled()
68 ******************************************************************************/
72 struct ProtectedPool
*pool
= NULL
;
74 /* puddleSize must not be smaller than threshSize */
75 if(puddleSize
>= threshSize
)
79 /* Round puddleSize up to be a multiple of MEMCHUNK_TOTAL. */
80 puddleSize
= (puddleSize
+ MEMCHUNK_TOTAL
- 1) & ~(MEMCHUNK_TOTAL
- 1);
83 Allocate memory for the Pool structure using the same requirements
84 as for the whole pool (to make it shareable, residentable or
88 poolstruct_size
= (requirements
& MEMF_SEM_PROTECTED
) ? sizeof(struct ProtectedPool
) :
91 pool
=(struct ProtectedPool
*)AllocMem(poolstruct_size
, requirements
& ~MEMF_SEM_PROTECTED
);
95 NEWLIST((struct List
*)&pool
->pool
.PuddleList
);
96 NEWLIST((struct List
*)&pool
->pool
.BlockList
);
99 pool
->pool
.Requirements
= requirements
;
100 pool
->pool
.PuddleSize
= puddleSize
;
101 pool
->pool
.ThreshSize
= threshSize
;
103 if (requirements
& MEMF_SEM_PROTECTED
)
105 InitSemaphore(&pool
->sem
);
109 } /* if(puddleSize >= threshSize) */