New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / compiler / alib / liballocpooled.c
blobc92630f7edcc8b0d668126573f2e9d64abfae69b
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 Original version from libnix
4 $Id$
5 */
7 #include "pool.h"
8 #include <proto/exec.h>
10 /*****************************************************************************
12 NAME */
13 #include <proto/alib.h>
15 APTR LibAllocPooled (
17 /* SYNOPSIS */
18 APTR pool,
19 ULONG memSize)
21 /* FUNCTION
23 INPUTS
25 RESULT
27 NOTES
29 EXAMPLE
31 BUGS
33 SEE ALSO
35 INTERNALS
37 HISTORY
38 06.12.96 digulla Created after original from libnix
40 ******************************************************************************/
42 # define poolHeader ((POOL *)pool)
43 AROS_GET_SYSBASE_OK
44 ULONG *puddle = NULL;
46 if (SysBase->LibNode.lib_Version >= 39)
47 return (AllocPooled (pool, memSize));
49 if (poolHeader != NULL && memSize != 0)
51 ULONG size;
53 if (poolHeader->ThreshSize > memSize)
55 struct MemHeader * a = (struct MemHeader *)poolHeader->PuddleList.mlh_Head;
57 for(;;)
59 if (a->mh_Node.ln_Succ!=NULL)
61 if (a->mh_Node.ln_Type
62 && (puddle = (ULONG *)Allocate (a, memSize)) != NULL
64 break;
66 a = (struct MemHeader *)a->mh_Node.ln_Succ;
68 else
70 size = poolHeader->PuddleSize
71 + sizeof (struct MemHeader)
72 + 2 * sizeof (ULONG);
74 if (!(puddle = (ULONG *)AllocMem (size, poolHeader->MemoryFlags)) )
75 return NULL;
77 *puddle ++ = size;
79 a = (struct MemHeader *)puddle;
81 a->mh_Node.ln_Type = NT_MEMORY;
82 a->mh_Lower =
83 a->mh_First = (struct MemChunk *)(
84 (UBYTE *)a
85 + sizeof (struct MemHeader)
86 + sizeof (UBYTE *)
88 a->mh_First->mc_Next = NULL;
89 a->mh_Free =
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);
97 break;
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)
107 ULONG *p = puddle;
109 memSize += 7;
110 memSize >>= 3;
114 *p++=0;
115 *p++=0;
116 } while (--memSize);
119 else
121 size = memSize + sizeof (struct MinNode) + 2 * sizeof (ULONG);
123 if ((puddle = (ULONG *)AllocMem (size, poolHeader->MemoryFlags)))
125 *puddle ++ = size;
127 AddTail ((struct List *)&poolHeader->PuddleList
128 , (struct Node *)puddle
131 puddle = (ULONG *)((struct MinNode *)puddle + 1);
133 *puddle ++ = 0;
138 return puddle;
139 } /* LibAllocPooled */