The general concept of the free list is that it is a linked list of available blocks of free memory. It starts as a single block that is the size of the entire heap and ends up being broken into multiple pieces.
The allocated blocks belong to the users who called alloc(), so they don't appear on the free list.
Here's an example that may help you see what's happening.
freeHead -> block -> 0
14K
After a few alloc() calls with no dealloc() calls yet, the free list will still only have one block, and there will be a few blocks that Memory has given to users.
freeHead -> block -> 0
12.5K
(user1) block -> 0
1K
(user2) block -> 0
500
Now (user1) is deallocated, so it goes on the free list.
freeHead -> block -> block -> 0
12.5K 1K
(user2) block->0
500
The next alloc is a memory hog 8-)
freeHead -> block -> block -> 0
2.5K 1K
(user2) block->0
500
(user3) block->0
10K
But it wasn't in use very long and is deallocated so it goes on the end of the free list.
freeHead -> block -> block ->block -> 0
2.5K 1K 10K
(user2) block->0
500
Alloc() calls can use any of the blocks in the free list that are large enough to satisfy the request. (The algorithm that is in the videos is "first fit" so it finds the first block that is big enough.)
---------------
The other problem with writing a LinkedList class in Jack is that for Memory, the list elements (the blocks) are variable sized. Each block should be something like
int next; // pointer to next block
int size; // size of *data*
int data[size]; // user data
--Mark