Skip to content
Snippets Groups Projects
Commit a251199b authored by DocQuantum's avatar DocQuantum
Browse files

Optimized makefile for debugging, implemented free

parent 0e24b7ac
No related branches found
No related tags found
No related merge requests found
/.vscode /.vscode
mdriver mdriver
*.o *.o
description/vm-freespace.pdf
...@@ -2,23 +2,41 @@ ...@@ -2,23 +2,41 @@
# Students' Makefile for the Malloc Lab # Students' Makefile for the Malloc Lab
# #
CC = gcc # CC = gcc
CFLAGS = -Wall -O2 -m32 -g -std=gnu11 # CFLAGS = -Wall -O2 -m32 -g -std=gnu11
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
mdriver: $(OBJS) # build: $(OBJS)
$(CC) $(CFLAGS) -o mdriver $(OBJS) # $(CC) $(CFLAGS) -o mdriver $(OBJS)
# mdriver.o:
# $(CC) $(CFLAGS) mdriver.c fsecs.h fcyc.h clock.h memlib.h config.h mm.h
# memlib.o:
# $(CC) $(CFLAGS) memlib.c memlib.h
# mm.o:
# $(CC) $(CFLAGS) mm.c mm.h memlib.h
# fsecs.o:
# $(CC) $(CFLAGS) fsecs.c fsecs.h config.h
# fcyc.o:
# $(CC) $(CFLAGS) fcyc.c fcyc.h
# ftimer.o:
# $(CC) $(CFLAGS) ftimer.c ftimer.h config.h
# clock.o:
# $(CC) $(CFLAGS) clock.c clock.h
mdriver.o: mdriver.c fsecs.h fcyc.h clock.h memlib.h config.h mm.h # clean:
memlib.o: memlib.c memlib.h # rm -f *~ *.o mdriver
mm.o: mm.c mm.h memlib.h
fsecs.o: fsecs.c fsecs.h config.h
fcyc.o: fcyc.c fcyc.h
ftimer.o: ftimer.c ftimer.h config.h
clock.o: clock.c clock.h
clean: CC=gcc
rm -f *~ *.o mdriver CFLAGS=-I. -Wall -O2 -m32 -g -std=gnu11
DEPS = fsecs.h fcyc.h clock.h memlib.h config.h mm.h
OBJ = mdriver.o mm.o memlib.o fsecs.o fcyc.o clock.o ftimer.o
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
mdriver: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS)
clean:
rm -f *~ *.o mdriver
\ No newline at end of file
...@@ -126,6 +126,7 @@ void *mm_malloc(size_t size) ...@@ -126,6 +126,7 @@ void *mm_malloc(size_t size)
size_t asize; /* adjusted block size */ size_t asize; /* adjusted block size */
size_t extendsize; /* amount to extend heap if no fit */ size_t extendsize; /* amount to extend heap if no fit */
char *bp; char *bp;
//printf("call mm_malloc\n"); //printf("call mm_malloc\n");
/* Ignore spurious requests */ /* Ignore spurious requests */
...@@ -137,6 +138,7 @@ void *mm_malloc(size_t size) ...@@ -137,6 +138,7 @@ void *mm_malloc(size_t size)
asize = WSIZE + OVERHEAD; asize = WSIZE + OVERHEAD;
else else
asize = DSIZE * ((size + (OVERHEAD) + (DSIZE-1)) / DSIZE); asize = DSIZE * ((size + (OVERHEAD) + (DSIZE-1)) / DSIZE);
//printf("asize = %d\n", asize); //printf("asize = %d\n", asize);
/* Search the free list for a fit */ /* Search the free list for a fit */
...@@ -148,14 +150,17 @@ void *mm_malloc(size_t size) ...@@ -148,14 +150,17 @@ void *mm_malloc(size_t size)
/* No fit found. Get more memory and place the block */ /* No fit found. Get more memory and place the block */
extendsize = MAX(asize,CHUNKSIZE); extendsize = MAX(asize,CHUNKSIZE);
//printf("extendsize = %d\n", extendsize); //printf("extendsize = %d\n", extendsize);
if ((bp = extend_heap(extendsize/WSIZE)) == NULL) if ((bp = extend_heap(extendsize/WSIZE)) == NULL) {
{
printf("mm_malloc = NULL\n"); printf("mm_malloc = NULL\n");
return NULL; return NULL;
} }
//printf("return address = %p\n", bp); //printf("return address = %p\n", bp);
place(bp, asize); place(bp, asize);
//mm_checkheap(1); //mm_checkheap(1);
return bp; return bp;
} }
/* $end mmmalloc */ /* $end mmmalloc */
...@@ -166,9 +171,12 @@ void *mm_malloc(size_t size) ...@@ -166,9 +171,12 @@ void *mm_malloc(size_t size)
/* $begin mmfree */ /* $begin mmfree */
void mm_free(void *bp) void mm_free(void *bp)
{ {
//printf("call mm_free\n"); if(!GET_ALLOC(HDRP(bp))){
*(size_t *)(HDRP(bp)) = *(size_t *)(HDRP(bp)) + 1;
} else {
fprintf(stderr, "Error: memory not alloced or corrupted");
}
/* You need to implement this function */
} }
/* $end mmfree */ /* $end mmfree */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment