line breaks
This commit is contained in:
@@ -76,7 +76,7 @@ root: 105
|
||||
## 25.6 Garbage Collection Technique #2: Stop and Copy
|
||||
|
||||
1. Split memory in half (working memory and copy memory).
|
||||
2. When out of working memory, stop computation and begin garbage collection.
|
||||
2. When out of working memory, stop computation and begin garbage collection.
|
||||
(a) Place scan and free pointers at the start of the copy memory.
|
||||
(b) Copy the root to copy memory, incrementing free. Whenever a node is copied from working memory, leave a forwarding address to its new location in copy memory in the left address slot of its old location.
|
||||
(c) Starting at the scan pointer, process the left and right pointers of each node. Look for their locations in working memory. If the node has already been copied (i.e., it has a forwarding address), update the reference. Otherwise, copy the location (as before) and update the reference.
|
||||
@@ -114,11 +114,11 @@ free:
|
||||
1. Add a mark bit to each location in memory.
|
||||
2. Keep a free pointer to the head of the free list.
|
||||
3. When memory runs out, stop computation, clear the mark bits and begin garbage collection.
|
||||
4. Mark
|
||||
4. Mark
|
||||
(a) Start at the root and follow the accessible structure (keeping a stack of where you still need to go).
|
||||
(b) Mark every node you visit.
|
||||
(c) Stop when you see a marked node, so you don’t go into a cycle.
|
||||
5. Sweep
|
||||
5. Sweep
|
||||
(a) Start at the end of memory, and build a new free list.
|
||||
(b) If a node is unmarked, then it’s garbage, so hook it into the free list by chaining the left pointers.
|
||||
|
||||
@@ -143,16 +143,21 @@ stack:
|
||||
## 25.10 Garbage Collection Comparison
|
||||
|
||||
- Reference Counting:
|
||||
- + fast and incremental
|
||||
|
||||
- \+ fast and incremental
|
||||
- – can’t handle cyclical data structures!
|
||||
- ? requires ∼33% extra memory (1 integer per node)
|
||||
|
||||
- Stop & Copy:
|
||||
|
||||
– requires a long pause in program execution
|
||||
+ can handle cyclical data structures!
|
||||
– requires 100% extra memory (you can only use half the memory)
|
||||
+ runs fast if most of the memory is garbage (it only touches the nodes reachable from the root)
|
||||
+ data is clustered together and memory is “de-fragmented”
|
||||
|
||||
- Mark-Sweep:
|
||||
|
||||
– requires a long pause in program execution
|
||||
+ can handle cyclical data structures!
|
||||
+ requires ∼1% extra memory (just one bit per node)
|
||||
|
||||
Reference in New Issue
Block a user