-
Notifications
You must be signed in to change notification settings - Fork 0
Structure
###Node
In order to keep track of memory chunks handed out to the system, their sizes and whether or not they are free to use, a structure called node was implemented. This node is implemented as a struct in C and contains the variables needed to keep track the above and also to serve as a node in a double-linked list.
/*Holds meta data for the memory chunks*/
struct node{
/*Points to the next memory node*/
struct node* prev;
/*Points to the prev memory node*/
struct node* next;
/*The size of the memory this node points to*/
size_t size;
/*0 is not free, otherwise free*/
int free;
/*Points to the memory that the user can use*/
void* chunk_pointer;
};######Graphical representation

###Free list The free list keeps track of all nodes created by malloc. The list can then be searched to find memory chunks that can be reused for further mallocs. The list is created by linking many nodes together into a double-linked list. We've chosen double-links in order to easily keep track of both neighbors to any node.
######Graphical representation

###Quick list The quick list is a structure that only appears when strategy is set to quick fit. It's represented as an array of free lists. Each free list contains free (unused) nodes of a specific 'quick size'. Nodes will then be taken out and put back into it's free list under the lifespan of a program.