























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
























CSE351, Autumn 2018
L26: Memory Allocation III
https://xkcd.com/835/
CSE351, Autumn 2018
L26: Memory Allocation III
CSE351, Autumn 2018
L26: Memory Allocation III
Size class(in bytes)^1632 48‐64 80‐inf
CSE351, Autumn 2018
L26: Memory Allocation III
-^ e.g. when scanning free list for
CSE351, Autumn 2018
L26: Memory Allocation III
CSE351, Autumn 2018
L26: Memory Allocation III
CSE351, Autumn 2018
L26: Memory Allocation III
CSE351, Autumn 2018
L26: Memory Allocation III
Root nodesHeap nodes
reachable not reachable(garbage)
CSE351, Autumn 2018
L26: Memory Allocation III
CSE351, Autumn 2018
L26: Memory Allocation III
Mark bit set
free free
CSE351, Autumn 2018
L26: Memory Allocation III
ptr^ mark(
ptr^ p)^ {
//^ p:^ some
word^ in
a^ heap^
block
if^ (!is_ptr(p))
return
;^ //^ do
nothing
if^ not^
pointer
if^ (markBitSet(p))
return ;
//^ check
if^ already
marked
setMarkBit(p);
//^ set^ the
mark^ bit
for^ (i=0;
i<length(p);
i++)^ //
recursively
call^ mark
on
mark(p[i]);
//^ all
words^ in
the^ block
Non‐testableMaterial Mark bit set
CSE351, Autumn 2018
L26: Memory Allocation III
ptr^ sweep(
ptr^ p,^ ptr
end)^ {^
//^ ptrs^
to^ start
&^ end^ of
heap
while^ (p
<^ end)^
//^ while
not^ at^
end^ of^ heap
if^ (markBitSet(p))
//^ check
if^ block
is^ marked
clearMarkBit(p);
//^ if^ so,
reset^ mark
bit
else^ if^
(allocateBitSet(p))
//^ if^ not
marked,
but^ allocated
free(p);
//^ free^
the^ block
p^ +=^ length(p);
//^ adjust
pointer
to^ next
block
Non‐testableMaterial
Mark bit set
free free
CSE351, Autumn 2018
L26: Memory Allocation III
Program stop Slide possible?^
Fixes:
CSE351, Autumn 2018
L26: Memory Allocation III