@@ -22,20 +22,55 @@ later time. Wikipedia also has a [summary](https://en.wikipedia.org/wiki/Memory_
22
22
## Example
23
23
![ ] ( amalloc.gif )
24
24
25
+ ## Usage
26
+ ```
27
+ usage: amalloc [-speed={step|slow|norm|fast|inst}]
28
+ -speed The time between each frame in the animation
29
+ step: wait for user input
30
+ slow: wait 1.5s
31
+ norm: wait 1.0s (default)
32
+ fast: wait 0.5s
33
+ inst: wait 0.0s
34
+ ```
35
+ Once you are running the code the following commands are valid. To keep
36
+ the animation less crowded, variables are limited to single characters.
37
+ ```
38
+ >>> <char> = malloc(<size>)
39
+ >>> free(<char>)
40
+
41
+ >>> x = malloc(4)
42
+ >>> y = malloc(7)
43
+ >>> free(x)
44
+ >>> free(y)
45
+ ```
46
+
25
47
## Install
26
48
You can build the executable
27
49
```
28
- $ git clone https://github.com/NithinChintala/amalloc.git
50
+ $ git clone https://github.com/NithinChintala/amalloc.git && cd amalloc
29
51
$ go build
30
52
$ ./amalloc
31
53
```
32
54
Or run it as a script
33
55
```
34
- $ git clone https://github.com/NithinChintala/amalloc.git
56
+ $ git clone https://github.com/NithinChintala/amalloc.git && cd amalloc
35
57
$ go run main.go
36
58
```
37
59
38
60
# How Does it Work?
61
+ At a high level the code is running a Finite State Machine. Each state is
62
+ rendered in the animation and calling malloc / free alters the state of
63
+ the animation. For all the transitions see below. You always start in the
64
+ Idle state and wait for some user input. All other states go on to the
65
+ next state based on the input speed. The animation will always show what
66
+ state is currently being rendered.
67
+ ![ ] ( fsm.png )
68
+
69
+
70
+ These are the ways the headers and cells are represented. The next and prev
71
+ sections represent indexes each byte in the 16 byte heap. Since it takes
72
+ 4 bits to represent 16 location, a NULL pointer is represented as 11111 or
73
+ 5 ones in a row.
39
74
** Header** - 1 byte
40
75
```
41
76
used unused
@@ -64,5 +99,3 @@ $ go run main.go
64
99
65
100
[0b00111111, 0b00000100] == {used: false, index: 1, prev: 31, next: 4}
66
101
```
67
-
68
- ![ ] ( fsm.png )
0 commit comments