26 printf(
"Heap Loc Ptr %d :: total size %d\r\n", (
int)
heapLoc, ((
int)((
int)initialHeapSize +
sizeof(
lmcb_t) +
sizeof(
cmcb_t))));
55 cmcb_t * allocatedCMCB = 0;
56 node_t * itNode = mcbFreeList.head.next;
57 for(; itNode != &(mcbFreeList.tail); itNode = itNode->next)
61 if(((
cmcb_t*)itNode->data)->mcbBlockSize >= totalBlockSize)
65 allocatedCMCB = ((
cmcb_t*)itNode->data);
84 cmcb_t* followCMCB = (
cmcb_t*)((
void*)allocatedCMCB + totalBlockSize);
125 printf(
"%s",
"\r\nAllocated Memory Blocks\r\n");
131 printf(
"%s",
"\r\nFree Memory Blocks\r\n");
146 if(((
cmcb_t*)mcb)->blockStartAddress == blockStartAddress)
150 return (((
cmcb_t*)mcb)->blockStartAddress < blockStartAddress)?-1:1;
158 cmcb_t* foundCMCB = (foundNode)?(
cmcb_t*)foundNode->data:0;
232 if(mcbAllocList.head.next == &mcbAllocList.tail)
return 0;
242 return "ERROR_BLOCK_NOT_FOUND";
244 return "ERROR_BLOCK_NOT_ALLOCATED";
246 return "ERROR_NOT_ENOUGH_MEMORY";
248 return "ACCESS_DENIED";
252 return "ERROR_UNKNOWN";
254 return "ERROR_UNKNOWN";
288 printf(
"HEAP TEST%s",
"\r\n");
289 printf(
"%s",
"Alloc list\r\n")
291 printf(
"%s",
"free list\r\n")
299 printf(
"test int ptr %d\r\n",(
int)test);
301 for(*test = 0; *test < 5; (*test)++)
309 printf(
"%s",
"\r\nAlloc list\r\n")
311 printf(
"%s",
"\r\nfree list\r\n")
313 for(*test = 0; *test < 5; (*test)++)
322 printf(
"%s",
"\r\nAlloc list\r\n")
324 printf(
"%s",
"\r\nfree list\r\n")
const char * mcbTypeToString(e_mcb_type_t type)
int heapIsEmpty()
heapIsEmpty returns if the heap is empty.
typedef of linked list node (see s_ll_node).
const char * mcbResultToString(e_mcb_result_t result)
void setPrintFunction(linkedList_t *list, void(*newPrintFunc)(void *))
sets the function whose job it is to print the list to the screen.
void reclaimFreeMem()
reclaimFreeMem groups free blocks together if they are adjacent.
The s_cmcb struct the struct type for cmcb's -> defines the properties.
u32int kmalloc(u32int size)
void insertMCBIntoList(cmcb_t *blockToInsert)
insertMCBIntoList inserts the mcb into the list specified.
void setSearchComparisonFunction(linkedList_t *list, int(*newSearchFunc)(void *, void *))
sets the function whose job it is to compare the input data with the data in the list. the first void parameter will always be the data contained in the list, the second will be the data passed to the search function.
void initHeap(size_t initialHeapSize)
initHeap initializes the system heap by calling kmalloc with a valid byte size. Creates a CMCB at the...
node_t * removeNode(node_t *nodeToRemove)
will remove the node from the list. the list hierarchy will change to reflect the missing node...
pcb_t * currentOperatingProcess
void initLinkedList(linkedList_t *list)
initilize list and the optional array that backs the list
heapLocationPtr_t heapLoc
void printAlloc()
printAlloc prints the allocated memory blocks. Traverses through the allocated mcb list...
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
void printMCBFunc(void *cmcb)
printMCBFunc prints the type, block size, block pointer of the blocks in a given list.
typedef of linked list (see s_ll).
mcbAddressPtr_t blockStartAddress
int mcbCompareFunc(void *mcb, void *mcbToCompare)
mcbCompareFunc compares the start addresses of two mcbs.
e_mcb_result_t lastMCBError
mcbAddressPtr_t blockStartAddress
void printList(linkedList_t *list)
test function to show list functionality. uses const char* as test data
void * allocateMemFromHeap(size_t requestedSize)
allocateMemFromHeap takes the requested size and finds the first block that fits. Implements first fi...
The s_lmcb struct defines the properties of lmcb's.
void printFree()
printFree prints the free memory blocks. Traverses through the free mcb list.
e_mcb_result_t
The e_mcb_result_t enum defines the return status of functions working with MCBs. ...
e_mcb_type_t
The e_mcb_type_t enum defines the state of the MCBs.
void setInsertComparisonFunction(linkedList_t *list, int(*newCompFunc)(void *, void *))
takes in a function pointer and sets the library shared comparison pointer
mcbAddressPtr_t blockStopAddress
node_t * insertNode(linkedList_t *list, node_t *newNode)
Will insert the node into the list. This function will attempt to call the list's insert comparison f...
int freeHeapMem(void *blockAddress)
freeHeapMem takes the block address and frees the memory from the CMCB start to the LMCB end location...
int mcbSearchCompFunc(void *mcb, void *blockStartAddress)
mcbSearchCompFunc searches for the mcb that you want to compare with.
linkedList_t mcbAllocList
node_t * searchList(linkedList_t *listToSearch, void *data)
goes through the list using the list's comparison function to find the node which matches the data...
void heapTest()
heapTest test function to create sample mcbs.