diff options
| author | _ov4 <ov4@ov4.org> | 2026-11-03 07:15:51 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-11-03 07:15:51 +0000 |
| commit | c0eceda8b0e7d120c2facc595730921280846f67 (patch) | |
| tree | 3b8da3f5504e16929b44fc7bc348b6dc3a9ba323 /malloclab-handout | |
| parent | 25e78c6e27044b96812a15ebc85c9b6064053518 (diff) | |
finished implicit
Diffstat (limited to 'malloclab-handout')
| -rw-r--r-- | malloclab-handout/mm-implicit.cc | 10 | ||||
| -rw-r--r-- | 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<Args...> fmt, Args&&... args ) { #ifdef OV4_VERBOSE print(fmt, forward<Args>(args)...); + fflush(stdout); #endif } |
