From 27e75d248baf04bf6c1c012efd446ea5cae1d5dd Mon Sep 17 00:00:00 2001 From: anna_schlittenhardt Date: Sun, 24 Jan 2021 18:08:02 +0100 Subject: [PATCH] Added new function add_free() --- mm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm.c b/mm.c index 86f9c80..e3b4924 100644 --- a/mm.c +++ b/mm.c @@ -130,6 +130,12 @@ static void* extend_heap(size_t words); //////////////////////////////////////////////////////////////////////////////// /////////////////////////////// HELPER FUNCTIONS /////////////////////////////// //////////////////////////////////////////////////////////////////////////////// +static void add_free(void* ptr, size_t size) +{ + int szClass = getSzClass(size); + void* classPtr = seg_list[szClass]; +} + static void place(void *bp, size_t asize) { size_t csize = GET_SIZE(HDRP(bp)); @@ -152,7 +158,7 @@ static int getSzClass(size_t asize) { return i; } } - return LISTSIZE; + return LISTSIZE-1; } static void* best_fit(void* ptr, size_t asize) { @@ -313,6 +319,7 @@ void *mm_malloc(size_t size) void mm_free(void *ptr) { size_t size = GET_SIZE(HDRP(ptr)); + add_free(ptr, size); PUT(HDRP(ptr), PACK(size, 0)); PUT(FTRP(ptr), PACK(size, 0));