|
6 | 6 | Package weak provides weak pointers with the goal of memory efficiency.
|
7 | 7 | The primary use-cases for weak pointers are for implementing caches,
|
8 | 8 | canonicalization maps (like the unique package), and for tying together
|
9 |
| -the lifetimes of separate values. |
| 9 | +the lifetimes of separate values (for example, through a map with weak |
| 10 | +keys). |
10 | 11 |
|
11 | 12 | ## Advice
|
12 | 13 |
|
13 | 14 | This package is intended to target niche use-cases like the unique
|
14 |
| -package, not as a general replacement for regular Go pointers, maps, |
15 |
| -etc. |
16 |
| -Misuse of the structures in this package will generate unexpected and |
| 15 | +package, and the structures inside are not intended to be general |
| 16 | +replacements for regular Go pointers, maps, etc. |
| 17 | +Misuse of the structures in this package may generate unexpected and |
17 | 18 | hard-to-reproduce bugs.
|
18 | 19 | Using the facilities in this package to try and resolve out-of-memory
|
19 |
| -issues and/or memory leaks is very likely the wrong answer. |
| 20 | +issues requires careful consideration, and even so, will likely be the |
| 21 | +wrong answer if the solution does not fall into one of the listed |
| 22 | +use-cases above. |
20 | 23 |
|
21 | 24 | The structures in this package are intended to be an implementation
|
22 | 25 | detail of the package they are used by (again, see the unique package).
|
23 |
| -Avoid exposing weak structures across API boundaries, since that exposes |
24 |
| -users of your package to the subtleties of this package. |
| 26 | +If you're writing a package intended to be used by others, as a rule of |
| 27 | +thumb, avoid exposing the behavior of any weak structures in your package's |
| 28 | +API. |
| 29 | +Doing so will almost certainly make your package more difficult to use |
| 30 | +correctly. |
25 | 31 | */
|
26 | 32 | package weak
|
0 commit comments