Fixed performance of getSz

master
TuDatTr 2021-01-24 22:53:37 +01:00
parent 921a49c0fc
commit ad1dd76932
2 changed files with 8 additions and 9 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

@ -164,18 +164,17 @@ static void *place(void *ptr, size_t asize);
@param[in] asize size class to look for in segregated list @param[in] asize size class to look for in segregated list
@result Size class (i.e. index of segregated list) @result Size class (i.e. index of segregated list)
*/ */
static int getSzClass(size_t asize); static inline int getSzClass(size_t asize);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/////////////////////////////// HELPER FUNCTIONS /////////////////////////////// /////////////////////////////// HELPER FUNCTIONS ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static int getSzClass(size_t asize) { static inline int getSzClass(size_t asize) {
for (size_t i = 0; i < LISTSIZE; ++i) { int i;
if (asize == (1 << i)) { for (i = 0; (i < LISTSIZE-1) && (asize > 1); ++i) {
return i; asize >>= 1;
}
} }
return LISTSIZE-1; return i;
} }
static void *extend_heap(size_t size) static void *extend_heap(size_t size)