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
#
CC = gcc
# CFLAGS = -Wall -O2 -m32
CFLAGS = -Wall -O0 -m32 -g03 -pg
CFLAGS = -Wall -O2 -m32
# CFLAGS = -Wall -O0 -m32 -g03 -pg
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);
}
int list = 0;
size_t searchsize = asize;
while (list < LISTSIZE) {
if ((list == LISTSIZE- 1) || ((searchsize <= 1) && (seg_list[list] != NULL))) {
ptr = seg_list[list];
size_t sz = asize;
for (int i = 0;i < LISTSIZE; ++i) {
if ((i == LISTSIZE-1) || ((sz < 2) && (seg_list[i] != NULL))) {
ptr = seg_list[i];
while ((ptr != NULL) && (asize > GET_SIZE(HDRP(ptr))))
{
ptr = PRV_BLK(ptr);
@ -339,9 +338,7 @@ void *mm_malloc(size_t size)
if (ptr != NULL)
break;
}
searchsize >>= 1;
list++;
sz >>= 1;
}
if (ptr == NULL) {