| | 1 | '''Cheney's Copying Collector''' |
| | 2 | |
| | 3 | The Fenichel-Yochelson collector given in the [wiki:CopyingGarbageCollector] |
| | 4 | page has the disadvantage of using a recursive copying algorithm. Since |
| | 5 | Cheney's discovery of an efficient iterative technique for its implementation |
| | 6 | copying collection has proved popular with implementors. Although garbage |
| | 7 | collection technology has moved beyond simple stop-and-copy collection, this |
| | 8 | technique remains the most widely adopted basis for more sophisticated |
| | 9 | techniques, such as generational and incremental collectors. |
| | 10 | |
| | 11 | |
| | 12 | Cheney's algorithm: |
| | 13 | {{{ |
| | 14 | flip() = |
| | 15 | Fromspace, Tospace = Tospace, Fromspace |
| | 16 | top_of_space = Tospace + space_size |
| | 17 | scan = free = Tospace |
| | 18 | |
| | 19 | for R in roots |
| | 20 | R = copy(R) |
| | 21 | |
| | 22 | while scan < free |
| | 23 | for P in Children(scan) |
| | 24 | *P = copy(*P) |
| | 25 | scan = scan + size (scan) |
| | 26 | |
| | 27 | copy(P) = |
| | 28 | if forwarded(P) |
| | 29 | return forwarding_address(P) |
| | 30 | else |
| | 31 | addr = free |
| | 32 | move(P,free) |
| | 33 | free = free + size(P) |
| | 34 | forwarding_address(P) = addr |
| | 35 | return addr |
| | 36 | |
| | 37 | }}} |
| | 38 | |
| | 39 | |
| | 40 | extracted from:[[BR]] |
| | 41 | Garbage Collection: Algorithms for Automatic Dynamic Memory Management[[BR]] |
| | 42 | by Richard Jones and Rafael Sims[[BR]] |
| | 43 | [http://www.cs.kent.ac.uk/people/staff/rej/gc.html] |