|
1 | 1 | Smart-Pointers Example |
2 | 2 | ====================== |
3 | 3 |
|
4 | | -The [user_object_smart_pointer.f90] demonstrates the use of the |
5 | | -Smart-Pointers library. The file contains |
| 4 | +The [user_object_smart_pointer.f90] file demonstrates the use of Smart-Pointers, |
| 5 | +including |
6 | 6 |
|
7 | | -* A module that defines a `user_object_t` and `user_object_ptr_t` types, |
8 | | -* A submodule defining a constructor funciton and a `free` final subroutin, |
9 | | -* A main program with a `block` construct that forces finalization of |
10 | | - the `user_object` entity declared in the main program. |
| 7 | +* A module that defines `user_object_t` and `user_object_ptr_t` types, |
| 8 | +* A submodule defining a constructor funciton and a `free` final subroutine, |
| 9 | +* A main program with a `block` construct that causes finalization of |
| 10 | + the `user_object` when the program reaches the `end block` statement. |
11 | 11 |
|
12 | 12 | This example exhibits several important subtleties: |
13 | 13 |
|
14 | 14 | 1. Smart-Pointers automate object finalization, eliminating the need |
15 | | - for `allocatable` objects. |
| 15 | + for `allocatable` objects. |
16 | 16 | 2. The main program source-allocates a raw `user_object` pointer and |
17 | 17 | then passes the pointer to a `user_object_ptr_t()` constructor. |
18 | 18 | 3. The `user_object_ptr_t()` constructor nullifies the received pointer |
19 | 19 | to encourage the intended practice in which all pointers associated |
20 | 20 | with the object are reference-counted pointers. |
21 | 21 | 4. All assignments in the main program and its internal subroutine |
22 | | - perform shallow copies, thereby creating new references to one object |
23 | | - without copying the object. |
| 22 | + perform shallow copies, thereby creating new references to |
| 23 | + `user_object` without copying the object. |
24 | 24 |
|
25 | | -Running the example with the following command: |
| 25 | +Run the example as follows: |
26 | 26 | ``` |
27 | 27 | fpm run --example user_object_smart_pointer --compiler nagfor --flag -fpp |
28 | 28 | ``` |
29 | | -should produce the following output: |
| 29 | +which should produce the following output: |
30 | 30 | ``` |
31 | 31 | Allocating user_object pointer. |
32 | 32 | Defining smart_pointer_1. |
|
0 commit comments