line breaks
This commit is contained in:
@@ -78,11 +78,8 @@ root: 105
|
|||||||
1. Split memory in half (working memory and copy memory).
|
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.
|
(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,
|
(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.
|
||||||
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.
|
||||||
(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.
|
|
||||||
(d) Repeat until scan == free.
|
(d) Repeat until scan == free.
|
||||||
(e) Swap the roles of the working and copy memory.
|
(e) Swap the roles of the working and copy memory.
|
||||||
|
|
||||||
@@ -146,9 +143,9 @@ stack:
|
|||||||
## 25.10 Garbage Collection Comparison
|
## 25.10 Garbage Collection Comparison
|
||||||
|
|
||||||
- Reference Counting:
|
- Reference Counting:
|
||||||
+ fast and incremental
|
- + fast and incremental
|
||||||
– can’t handle cyclical data structures!
|
- – can’t handle cyclical data structures!
|
||||||
? requires ∼33% extra memory (1 integer per node)
|
- ? requires ∼33% extra memory (1 integer per node)
|
||||||
- Stop & Copy:
|
- Stop & Copy:
|
||||||
– requires a long pause in program execution
|
– requires a long pause in program execution
|
||||||
+ can handle cyclical data structures!
|
+ can handle cyclical data structures!
|
||||||
@@ -171,9 +168,13 @@ enormous beast of a programming language (but that doesn’t stop people from tr
|
|||||||
we can do? Yes, we can use Smart Pointers to gain some of the features of garbage collection.
|
we can do? Yes, we can use Smart Pointers to gain some of the features of garbage collection.
|
||||||
Some examples below are modified from these nice online references:
|
Some examples below are modified from these nice online references:
|
||||||
[http://ootips.org/yonat/4dev/smart-pointers.html](http://ootips.org/yonat/4dev/smart-pointers.html)
|
[http://ootips.org/yonat/4dev/smart-pointers.html](http://ootips.org/yonat/4dev/smart-pointers.html)
|
||||||
|
|
||||||
[http://www.codeproject.com/KB/stl/boostsmartptr.aspx](http://www.codeproject.com/KB/stl/boostsmartptr.aspx)
|
[http://www.codeproject.com/KB/stl/boostsmartptr.aspx](http://www.codeproject.com/KB/stl/boostsmartptr.aspx)
|
||||||
|
|
||||||
[http://en.wikipedia.org/wiki/Smart_pointer](http://en.wikipedia.org/wiki/Smart_pointer)
|
[http://en.wikipedia.org/wiki/Smart_pointer](http://en.wikipedia.org/wiki/Smart_pointer)
|
||||||
|
|
||||||
[http://www.boost.org/doc/libs/1_48_0/libs/smart_ptr/smart_ptr.htm](http://www.boost.org/doc/libs/1_48_0/libs/smart_ptr/smart_ptr.htm)
|
[http://www.boost.org/doc/libs/1_48_0/libs/smart_ptr/smart_ptr.htm](http://www.boost.org/doc/libs/1_48_0/libs/smart_ptr/smart_ptr.htm)
|
||||||
|
|
||||||
[http://www.acodersjourney.com/2016/05/top-10-dumb-mistakes-avoid-c-11-smart-pointers/](http://www.acodersjourney.com/2016/05/top-10-dumb-mistakes-avoid-c-11-smart-pointers/)
|
[http://www.acodersjourney.com/2016/05/top-10-dumb-mistakes-avoid-c-11-smart-pointers/](http://www.acodersjourney.com/2016/05/top-10-dumb-mistakes-avoid-c-11-smart-pointers/)
|
||||||
|
|
||||||
## 25.12 What’s a Smart Pointer?
|
## 25.12 What’s a Smart Pointer?
|
||||||
|
|||||||
Reference in New Issue
Block a user