2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 Original version from libnix
8 #include <proto/exec.h>
10 /*****************************************************************************
13 #include <proto/alib.h>
38 06.12.96 digulla Created after original from libnix
40 ******************************************************************************/
42 # define poolHeader ((POOL *)pool)
45 if (SysBase
->LibNode
.lib_Version
>= 39)
46 return (AllocPooled (pool
, memSize
));
48 if (poolHeader
!= NULL
&& memSize
!= 0)
52 if (poolHeader
->ThreshSize
> memSize
)
54 struct MemHeader
* a
= (struct MemHeader
*)poolHeader
->PuddleList
.mlh_Head
;
58 if (a
->mh_Node
.ln_Succ
!=NULL
)
60 if (a
->mh_Node
.ln_Type
61 && (puddle
= (ULONG
*)Allocate (a
, memSize
)) != NULL
65 a
= (struct MemHeader
*)a
->mh_Node
.ln_Succ
;
69 size
= poolHeader
->PuddleSize
70 + sizeof (struct MemHeader
)
73 if (!(puddle
= (ULONG
*)AllocMem (size
, poolHeader
->MemoryFlags
)) )
78 a
= (struct MemHeader
*)puddle
;
80 a
->mh_Node
.ln_Type
= NT_MEMORY
;
82 a
->mh_First
= (struct MemChunk
*)(
84 + sizeof (struct MemHeader
)
87 a
->mh_First
->mc_Next
= NULL
;
89 a
->mh_First
->mc_Bytes
= poolHeader
->PuddleSize
;
90 a
->mh_Upper
= (char *)a
->mh_First
+ a
->mh_Free
;
92 AddHead ((struct List
*)&poolHeader
->PuddleList
, &a
->mh_Node
);
94 puddle
= (ULONG
*)Allocate (a
, memSize
);
101 We do have to clear memory here. It may have been dirtied
102 by somebody using it beforehand.
104 if (poolHeader
->MemoryFlags
& MEMF_CLEAR
)
120 size
= memSize
+ sizeof (struct MinNode
) + 2 * sizeof (ULONG
);
122 if ((puddle
= (ULONG
*)AllocMem (size
, poolHeader
->MemoryFlags
)))
126 AddTail ((struct List
*)&poolHeader
->PuddleList
127 , (struct Node
*)puddle
130 puddle
= (ULONG
*)((struct MinNode
*)puddle
+ 1);
138 } /* LibAllocPooled */