-
Notifications
You must be signed in to change notification settings - Fork 0
/
heapmgr1.c~
47 lines (33 loc) · 833 Bytes
/
heapmgr1.c~
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
enum {FALSE, TRUE};
enum {MIN_UNITS_FROM_OS = 512};
static Chunk_T oHeapStart = NULL;
static Chunk_T oHeapEnd = NULL;
static Chunk_T oFreeList = NULL;
void HeapMgr_setToFront(Chunk_T oChunk);
void HeapMgr_removeFromList(Chunk_T oChunk)
{
}
void *HeapMgr_malloc(size_t uBytes)
{
size_t uUnits;
if (uBytes == 0)
return NULL;
/* initialize */
if (oHeapStart == NULL)
{
oHeapStart = (Chunk_T)sbrk(0);
oHeapEnd = oHeapStart;
}
/* determine units needed */
uUnits = Chunk_bytesToUnits(uBytes);
/* for each chunk in the free list */
for (oChunk = oFreeList;
oChunk != NULL;
oChunk = Chunk_getNextInList(oChunk))
{
/* if the current free list chunk is big enough */
if (uUnits <= Chunk_getUnits(oChunk))
{
}
}
}