Cheney's algorithm: Difference between revisions

Content deleted Content added
Cadrpear (talk | contribs)
m Sample algorithm: indent the pseudocode
Sample algorithm: Removed erroneous recursion
Line 21:
<source>
initialize() =
tospace = 0
fromspace = N/2
allocPtr = tospace
scanPtr = whatever -- only used during collection
</source>
 
Line 41 ⟶ 42:
<source>
collect() =
swap( fromspace, tospace )
allocPtr = tospace
rootscanPtr = copy(root)tospace
 
-- scan every root you've got
ForEach root in the stack -- or elsewhere
rroot = copy(rroot)
EndForEach
-- scan objects in the heap (including objects added by this loop)
While scanPtr points to an object o in the heap
ForEach reference r from o’o
r = copy(r)
EndForEach
scanPtr = scanPtr + o.size() -- points to the next object in the heap, if any
EndWhile
 
</source>
 
<source>
copy(o) =
If o has no forwarding address
o’ o' = allocPtr
allocPtr = allocPtr + size(oroot)
copy the contents of o to o’o'
forwarding-address(o) = o’o'
ForEach reference r from o’
r = copy(r)
EndForEach
EndIf
return forwarding-address(o)
 
</source>