Cheney's algorithm: Difference between revisions

Content deleted Content added
Equivalence to Tri-color abstraction: MOS advises against links in headers; better to state what the idea is clearly instead of minimalist phrase
No edit summary
Line 17:
 
Because the strategy is to exhaust all live references, and then all references in referenced objects, this is known as a ''breadth-first'' list copying garbage collection scheme.
 
* '''Sample Algorithm.'''
 
initialize() =
tospace = 0
fromspace = N/2
allocPtr = tospace
 
allocate(n) =
If allocPtr + n > tospace + N/2
collect()
EndIf
If allocPtr + n > tospace + N/2
fail “insufficient memory”
EndIf
o = allocPtr
allocPtr = allocPtr + n
return o
 
collect() =
swap( fromspace, tospace )
allocPtr = tospace
root = copy(root)
 
copy(o) =
If o has no forwarding address
o’ = allocPtr
allocPtr = allocPtr + size(o)
copy the contents of o to o’
forwarding-address(o) = o’
ForEach reference r from o’
r = copy(r)
EndForEach
EndIf
return forwarding-address(o)
 
== Semispace ==
Line 48 ⟶ 83:
| last2 = Yochelson
| first2 = Jerome C.
}}
* {{cite journal
| last = Byers| first = Rick
| title = Garbage Collection Algorithms
| journal = Garbage Collection Algorithms
| volume = 12 | issue = 11 |year=2007 | pages = 3-4
| url = http://courses.cs.washington.edu/courses/csep521/07wi/prj/rick.pdf
}}
* [http://www.cs.umd.edu/class/fall2002/cmsc631/cheney/cheney.html Tutorial] at the [[University of Maryland, College Park]]