Content deleted Content added
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(
allocPtr = tospace
-- scan every root you've got
ForEach root in the stack -- or elsewhere
-- scan objects in the heap (including objects added by this loop)
While scanPtr points to an object o in the heap
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
allocPtr = allocPtr + size(
copy the contents of o to
forwarding-address(o) =
▲ ForEach reference r from o’
▲ r = copy(r)
▲ EndForEach
EndIf
return forwarding-address(o)
</source>
|