while -> for

master
TuDatTr 2021-01-24 21:56:10 +01:00
parent 96fcf9f5c4
commit a8a03d0d36
2 changed files with 7 additions and 10 deletions

View File

@ -2,8 +2,8 @@
# Students' Makefile for the Malloc Lab # Students' Makefile for the Malloc Lab
# #
CC = gcc CC = gcc
# CFLAGS = -Wall -O2 -m32 CFLAGS = -Wall -O2 -m32
CFLAGS = -Wall -O0 -m32 -g03 -pg # CFLAGS = -Wall -O0 -m32 -g03 -pg
OBJS = mdriver.o mm.o memlib.o fsecs.o fcyc.o clock.o ftimer.o OBJS = mdriver.o mm.o memlib.o fsecs.o fcyc.o clock.o ftimer.o

13
mm.c
View File

@ -327,11 +327,10 @@ void *mm_malloc(size_t size)
asize = ALIGN(size+DSIZE); asize = ALIGN(size+DSIZE);
} }
int list = 0; size_t sz = asize;
size_t searchsize = asize; for (int i = 0;i < LISTSIZE; ++i) {
while (list < LISTSIZE) { if ((i == LISTSIZE-1) || ((sz < 2) && (seg_list[i] != NULL))) {
if ((list == LISTSIZE- 1) || ((searchsize <= 1) && (seg_list[list] != NULL))) { ptr = seg_list[i];
ptr = seg_list[list];
while ((ptr != NULL) && (asize > GET_SIZE(HDRP(ptr)))) while ((ptr != NULL) && (asize > GET_SIZE(HDRP(ptr))))
{ {
ptr = PRV_BLK(ptr); ptr = PRV_BLK(ptr);
@ -339,9 +338,7 @@ void *mm_malloc(size_t size)
if (ptr != NULL) if (ptr != NULL)
break; break;
} }
sz >>= 1;
searchsize >>= 1;
list++;
} }
if (ptr == NULL) { if (ptr == NULL) {