2 Copyright © 1995-2001, 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)
46 if (SysBase
->LibNode
.lib_Version
>= 39)
47 return (AllocPooled (pool
, memSize
));
49 if (poolHeader
!= NULL
&& memSize
!= 0)
53 if (poolHeader
->ThreshSize
> memSize
)
55 struct MemHeader
* a
= (struct MemHeader
*)poolHeader
->PuddleList
.mlh_Head
;
59 if (a
->mh_Node
.ln_Succ
!=NULL
)
61 if (a
->mh_Node
.ln_Type
62 && (puddle
= (ULONG
*)Allocate (a
, memSize
)) != NULL
66 a
= (struct MemHeader
*)a
->mh_Node
.ln_Succ
;
70 size
= poolHeader
->PuddleSize
71 + sizeof (struct MemHeader
)
74 if (!(puddle
= (ULONG
*)AllocMem (size
, poolHeader
->MemoryFlags
)) )
79 a
= (struct MemHeader
*)puddle
;
81 a
->mh_Node
.ln_Type
= NT_MEMORY
;
83 a
->mh_First
= (struct MemChunk
*)(
85 + sizeof (struct MemHeader
)
88 a
->mh_First
->mc_Next
= NULL
;
90 a
->mh_First
->mc_Bytes
= poolHeader
->PuddleSize
;
91 a
->mh_Upper
= (char *)a
->mh_First
+ a
->mh_Free
;
93 AddHead ((struct List
*)&poolHeader
->PuddleList
, &a
->mh_Node
);
95 puddle
= (ULONG
*)Allocate (a
, memSize
);
102 We do have to clear memory here. It may have been dirtied
103 by somebody using it beforehand.
105 if (poolHeader
->MemoryFlags
& MEMF_CLEAR
)
121 size
= memSize
+ sizeof (struct MinNode
) + 2 * sizeof (ULONG
);
123 if ((puddle
= (ULONG
*)AllocMem (size
, poolHeader
->MemoryFlags
)))
127 AddTail ((struct List
*)&poolHeader
->PuddleList
128 , (struct Node
*)puddle
131 puddle
= (ULONG
*)((struct MinNode
*)puddle
+ 1);
139 } /* LibAllocPooled */