From c0eceda8b0e7d120c2facc595730921280846f67 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 3 Nov 2026 07:15:51 +0000 Subject: finished implicit --- malloclab-handout/mm-implicit.cc | 10 +++++++--- malloclab-handout/util/mm-implicit.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/malloclab-handout/mm-implicit.cc b/malloclab-handout/mm-implicit.cc index 0cfc13f..ecc40a9 100644 --- a/malloclab-handout/mm-implicit.cc +++ b/malloclab-handout/mm-implicit.cc @@ -113,6 +113,9 @@ void *mm_malloc(size_t size) continue; } + // really alloc + // never gonna iterate again + size_t oldsize = get_size(status); set_size(status, newsize); @@ -129,7 +132,8 @@ void *mm_malloc(size_t size) size_t free_status = 0; set_size(free_status, oldsize - newsize); set_alloc(free_status, false); - set_prev_alloc(free_status, true); + set_prev_alloc(free_status, true); // becomes: ALLOC FREE + // so definitely prev_alloc=true for FREE part size_t free_header_p = p+newsize; *(size_t*)(free_header_p) = free_status; sync_footer(free_header_p); @@ -139,9 +143,9 @@ void *mm_malloc(size_t size) // so need to update next prev_alloc else { - size_t p_next = get_size(*(size_t*)p); + size_t p_next = p + get_size(*(size_t*)p); if (p_next <= (size_t)mem_heap_hi()) - set_prev_alloc(*(size_t*)p, true); + set_prev_alloc(*(size_t*)p_next, true); } loggerln("return: {}" , (size_t)ret-(size_t)mem_heap_lo()); diff --git a/malloclab-handout/util/mm-implicit.h b/malloclab-handout/util/mm-implicit.h index 74e0f86..820310c 100644 --- a/malloclab-handout/util/mm-implicit.h +++ b/malloclab-handout/util/mm-implicit.h @@ -73,6 +73,7 @@ void logger( std::format_string fmt, Args&&... args ) { #ifdef OV4_VERBOSE print(fmt, forward(args)...); + fflush(stdout); #endif } -- cgit v1.3.1-4-g156e