| 1 |
|
| 2 |
|
| 3 |
Smart Pointers Example |
| 4 |
---------------------- |
| 5 |
|
| 6 |
This example shows the use of the various smart pointer classes |
| 7 |
available in ACE. |
| 8 |
|
| 9 |
There are two programs in this example. Each program implements a |
| 10 |
similar set of classes, but with a different style of using smart |
| 11 |
pointers. |
| 12 |
|
| 13 |
The Widget example is written such that objects may only pass raw |
| 14 |
pointers between them, and use smart pointers to manage the object |
| 15 |
lifetimes. An advantage of this style is the fine-grained control |
| 16 |
over the type of smart pointer used in each situation. For example, |
| 17 |
if you know that in a particular section of code there is no |
| 18 |
concurrency involved, you can strategise ACE_Refcounted_Auto_Ptr on |
| 19 |
ACE_Null_Mutex to eliminate locking overhead. Disadvantages of this |
| 20 |
style include greater programming complexity and certain ownership |
| 21 |
use cases not being easily supported. |
| 22 |
|
| 23 |
The Gadget example is written such that objects are always passed |
| 24 |
around using one of the ACE_Strong_Bound_Ptr/ACE_Weak_Bound_Ptr |
| 25 |
pair of smart pointers. The advantage of this style is the |
| 26 |
reduction in complexity of object lifetime management (almost as |
| 27 |
"good" as Java ;-) The disadvantage is that you pay a cost for the |
| 28 |
reference counting and locking overhead even in situations where it |
| 29 |
may not be strictly necessary. |