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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Daniel Shchur
malloc
Commits
edabbd8a
Commit
edabbd8a
authored
Oct 18, 2019
by
DocQuantum
Browse files
Options
Downloads
Patches
Plain Diff
Implemnted coalescing with next and back pointers.
parent
5bc551b9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mm.c
+40
-13
40 additions, 13 deletions
mm.c
with
40 additions
and
13 deletions
mm.c
+
40
−
13
View file @
edabbd8a
...
@@ -37,20 +37,11 @@
...
@@ -37,20 +37,11 @@
team_t
team
=
{
team_t
team
=
{
/* Team name */
/* Team name */
"Daniel Shchur"
,
"Daniel Shchur"
,
/* note that we will add a 10% bonus for
/* Full name */
* working alone */
/* the maximum number of members per team
* is four */
/* First member's full name */
"Daniel Shchur"
,
"Daniel Shchur"
,
/*
First member's e
mail address */
/*
E
mail address */
"daniel.shchur@huskers.unl.edu"
,
"daniel.shchur@huskers.unl.edu"
,
/* Second member's full name (leave
""
,
""
* blank if none) */
""
,
/* Second member's email address
* (leave blank if none) */
""
};
};
...
@@ -93,6 +84,7 @@ static void *extend_heap(size_t words);
...
@@ -93,6 +84,7 @@ static void *extend_heap(size_t words);
static
void
place
(
void
*
bp
,
size_t
asize
);
static
void
place
(
void
*
bp
,
size_t
asize
);
static
void
*
find_fit
(
size_t
asize
);
static
void
*
find_fit
(
size_t
asize
);
static
void
printblock
(
void
*
bp
);
static
void
printblock
(
void
*
bp
);
static
void
mm_coalesce
(
void
*
bp
);
/*
/*
* mm_init - Initialize the memory manager
* mm_init - Initialize the memory manager
...
@@ -180,7 +172,8 @@ void mm_free(void *bp)
...
@@ -180,7 +172,8 @@ void mm_free(void *bp)
}
}
if
(
!
GET_ALLOC
(
HDRP
(
bp
))){
if
(
!
GET_ALLOC
(
HDRP
(
bp
))){
*
HDRP
(
bp
)
=
*
HDRP
(
bp
)
|
1
;
*
HDRP
(
bp
)
|=
1
;
mm_coalesce
(
bp
);
}
else
{
}
else
{
fprintf
(
stderr
,
"Error: memory not alloced or corrupted"
);
fprintf
(
stderr
,
"Error: memory not alloced or corrupted"
);
}
}
...
@@ -189,6 +182,40 @@ void mm_free(void *bp)
...
@@ -189,6 +182,40 @@ void mm_free(void *bp)
/* $end mmfree */
/* $end mmfree */
/**
* mm_coalesce - Coalesce the freespace around a block
*
* Given a block pointer that has been freed, find empty
* blocks near it to be combined into a large free chunk.
*
* TODO: coalesce previous chunks
*/
static
void
mm_coalesce
(
void
*
bp
)
{
//find next block
unsigned
int
nSize
=
0
;
if
(
GET_ALLOC
(
HDRP
(
NEXT_BLKP
(
bp
))))
{
nSize
=
GET_SIZE
(
NEXT_BLKP
(
bp
));
}
//find previous block
char
*
prev
;
unsigned
int
pSize
=
0
;
for
(
prev
=
heap_listp
;
GET_SIZE
(
prev
-
WSIZE
)
>
0
;
prev
=
NEXT_BLKP
(
prev
))
{
if
(
GET_ALLOC
(
HDRP
(
prev
))
&&
NEXT_BLKP
(
prev
)
==
bp
)
{
pSize
=
GET_SIZE
(
HDRP
(
prev
));
break
;
}
}
if
(
pSize
>
0
){
PUT
(
prev
,
PACK
(
pSize
+
nSize
+
GET_SIZE
(
HDRP
(
bp
)),
1
));
return
;
}
else
if
(
nSize
>
0
){
PUT
(
bp
,
PACK
(
nSize
+
GET_SIZE
(
HDRP
(
bp
)),
1
));
return
;
}
}
/*
/*
* mm_realloc - naive implementation of mm_realloc
* mm_realloc - naive implementation of mm_realloc
*
*
...
...
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