blob: 8a697e2a322aba701482d26526e9f466ca5cbbe1 (
plain)
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
|
Data Structures
===============
heap
top
free_head
free_tail
block
next_free
user_data
Functions
=========
malloc(heap)
if heap->top unset
heap->top = 0
return 0
elif heap->free_head unset
return ++heap->top
else
block = heap->free_head
if heap->free_head == heap->free_tail
unset heap->free_head
unset heap->free_tail
else
heap->free_head = heap->free_head->next_free
return block
free(heap, ptr)
if heap->free_tail unset
heap->free_head = heap->free_tail = ptr
else
heap->free_tail->next_free = ptr
heap->free_tail = ptr
Return register:
__mr
|