forked from ApolloTeam-dev/ApolloOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallocvecpooled.c
More file actions
88 lines (65 loc) · 1.94 KB
/
Copy pathallocvecpooled.c
File metadata and controls
88 lines (65 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Copyright � 2003-2013, The AROS Development Team. All rights reserved.
$Id$
*/
#include <aros/libcall.h>
#include "exec_intern.h"
#include <aros/debug.h>
/*****************************************************************************
NAME */
#include <exec/memory.h>
#include <exec/memheaderext.h>
#include <proto/exec.h>
AROS_LH2(APTR, AllocVecPooled,
/* SYNOPSIS */
AROS_LHA(APTR, poolHeader, A0),
AROS_LHA(IPTR, memSize, D0),
/* LOCATION */
struct ExecBase *, SysBase, 169, Exec)
/* FUNCTION
Allocate memory out of a private memory pool and remember the size.
The memory must be freed with FreeVecPooled(), or by deallocating
the entire pool with DeletePool().
INPUTS
poolHeader - Handle of the memory pool
memSize - Number of bytes you want to get
RESULT
A pointer to the number of bytes you wanted or NULL if the memory
couldn't be allocated
NOTES
EXAMPLE
BUGS
SEE ALSO
CreatePool(), DeletePool(), FreeVecPooled()
INTERNALS
******************************************************************************/
{
AROS_LIBFUNC_INIT
struct MemHeaderExt *mhe = (struct MemHeaderExt *)poolHeader;
/* 0-sized allocation results in returning NULL (API guarantee) */
if(!memSize)
return NULL;
#ifdef HANDLE_MANAGED_MEM
if (IsManagedMem(mhe))
{
ULONG poolrequirements = (ULONG)(IPTR)mhe->mhe_MemHeader.mh_First;
if (mhe->mhe_Alloc)
return mhe->mhe_AllocVec(mhe, memSize, &poolrequirements);
else
return NULL;
}
else
#endif
{
IPTR *memory;
if (poolHeader == NULL) return NULL;
memSize += sizeof(IPTR);
memory = AllocPooled(poolHeader, memSize);
if (memory != NULL)
{
*memory++ = memSize;
}
return memory;
}
AROS_LIBFUNC_EXIT
} /* AllocVecPooled() */