2 Copyright � 1995-2013, The AROS Development Team. All rights reserved.
5 Desc: Allocate memory in a pool.
9 #include <aros/libcall.h>
11 #include "exec_intern.h"
12 #include "exec_util.h"
15 #include "exec_debug.h"
16 #ifndef DEBUG_AllocPooled
17 # define DEBUG_AllocPooled 0
23 #include <aros/debug.h>
28 /*****************************************************************************
31 #include <exec/memory.h>
32 #include <exec/memheaderext.h>
33 #include <proto/exec.h>
35 AROS_LH2(APTR
, AllocPooled
,
38 AROS_LHA(APTR
, poolHeader
, A0
),
39 AROS_LHA(IPTR
, memSize
, D0
),
42 struct ExecBase
*, SysBase
, 118, Exec
)
45 Allocate memory out of a private memory pool. The memory must be
46 freed with FreePooled(), or by deallocating the entire pool with
50 poolHeader - Handle of the memory pool
51 memSize - Number of bytes you want to get
54 A pointer to the number of bytes you wanted or NULL if the memory
64 CreatePool(), DeletePool(), FreePooled()
68 ******************************************************************************/
72 struct MemHeaderExt
*mhe
= (struct MemHeaderExt
*)poolHeader
;
74 /* 0-sized allocation results in returning NULL (API guarantee) */
78 if (IsManagedMem(mhe
))
80 ULONG poolrequirements
= (ULONG
)(IPTR
)mhe
->mhe_MemHeader
.mh_First
;
83 return mhe
->mhe_Alloc(mhe
, memSize
, &poolrequirements
);
89 struct TraceLocation tp
= CURRENT_LOCATION("AllocPooled");
90 struct Pool
*pool
= poolHeader
+ MEMHEADER_TOTAL
;
92 D(bug("AllocPooled 0x%p memsize %u by \"%s\"\n", poolHeader
, memSize
, GET_THIS_TASK
->tc_Node
.ln_Name
);)
94 /* Allocate from the specified pool with flags stored in pool header */
95 return InternalAllocPooled(poolHeader
, memSize
, pool
->Requirements
, &tp
, SysBase
);