Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
malloc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Daniel Shchur
malloc
Commits
a251199b
Commit
a251199b
authored
5 years ago
by
DocQuantum
Browse files
Options
Downloads
Patches
Plain Diff
Optimized makefile for debugging, implemented free
parent
0e24b7ac
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
Makefile
+32
-14
32 additions, 14 deletions
Makefile
mm.c
+45
-37
45 additions, 37 deletions
mm.c
with
78 additions
and
51 deletions
.gitignore
+
1
−
0
View file @
a251199b
/.vscode
mdriver
*.o
description/vm-freespace.pdf
This diff is collapsed.
Click to expand it.
Makefile
+
32
−
14
View file @
a251199b
...
...
@@ -2,23 +2,41 @@
# Students' Makefile for the Malloc Lab
#
CC
=
gcc
CFLAGS
=
-Wall
-O2
-m32
-g
-std
=
gnu11
#
CC = gcc
#
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)
$(
CC
)
$(
CFLAGS
)
-o
mdriver
$(
OBJS
)
# build: $(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
memlib.o
:
memlib.c memlib.h
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:
# rm -f *~ *.o mdriver
clean
:
rm
-f
*
~
*
.o mdriver
CC
=
gcc
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
This diff is collapsed.
Click to expand it.
mm.c
+
45
−
37
View file @
a251199b
...
...
@@ -126,6 +126,7 @@ void *mm_malloc(size_t size)
size_t
asize
;
/* adjusted block size */
size_t
extendsize
;
/* amount to extend heap if no fit */
char
*
bp
;
//printf("call mm_malloc\n");
/* Ignore spurious requests */
...
...
@@ -137,6 +138,7 @@ void *mm_malloc(size_t size)
asize
=
WSIZE
+
OVERHEAD
;
else
asize
=
DSIZE
*
((
size
+
(
OVERHEAD
)
+
(
DSIZE
-
1
))
/
DSIZE
);
//printf("asize = %d\n", asize);
/* Search the free list for a fit */
...
...
@@ -148,14 +150,17 @@ void *mm_malloc(size_t size)
/* No fit found. Get more memory and place the block */
extendsize
=
MAX
(
asize
,
CHUNKSIZE
);
//printf("extendsize = %d\n", extendsize);
if
((
bp
=
extend_heap
(
extendsize
/
WSIZE
))
==
NULL
)
{
if
((
bp
=
extend_heap
(
extendsize
/
WSIZE
))
==
NULL
)
{
printf
(
"mm_malloc = NULL
\n
"
);
return
NULL
;
}
//printf("return address = %p\n", bp);
place
(
bp
,
asize
);
//mm_checkheap(1);
return
bp
;
}
/* $end mmmalloc */
...
...
@@ -166,9 +171,12 @@ void *mm_malloc(size_t size)
/* $begin mmfree */
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 */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment