2024-11-15 20:42:32 +00:00
|
|
|
// Copyright 2024 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Package weak provides weak pointers with the goal of memory efficiency.
|
|
|
|
|
The primary use-cases for weak pointers are for implementing caches,
|
|
|
|
|
canonicalization maps (like the unique package), and for tying together
|
2024-12-04 19:33:26 +00:00
|
|
|
the lifetimes of separate values (for example, through a map with weak
|
|
|
|
|
keys).
|
2024-11-15 20:42:32 +00:00
|
|
|
|
2024-12-04 23:36:17 -05:00
|
|
|
# Advice
|
2024-11-15 20:42:32 +00:00
|
|
|
|
|
|
|
|
This package is intended to target niche use-cases like the unique
|
2024-12-04 19:33:26 +00:00
|
|
|
package, and the structures inside are not intended to be general
|
|
|
|
|
replacements for regular Go pointers, maps, etc.
|
|
|
|
|
Misuse of the structures in this package may generate unexpected and
|
2024-11-15 20:42:32 +00:00
|
|
|
hard-to-reproduce bugs.
|
|
|
|
|
Using the facilities in this package to try and resolve out-of-memory
|
2024-12-04 19:33:26 +00:00
|
|
|
issues requires careful consideration, and even so, will likely be the
|
|
|
|
|
wrong answer if the solution does not fall into one of the listed
|
|
|
|
|
use-cases above.
|
2024-11-15 20:42:32 +00:00
|
|
|
|
|
|
|
|
The structures in this package are intended to be an implementation
|
|
|
|
|
detail of the package they are used by (again, see the unique package).
|
2024-12-04 19:33:26 +00:00
|
|
|
If you're writing a package intended to be used by others, as a rule of
|
|
|
|
|
thumb, avoid exposing the behavior of any weak structures in your package's
|
|
|
|
|
API.
|
|
|
|
|
Doing so will almost certainly make your package more difficult to use
|
|
|
|
|
correctly.
|
2024-11-15 20:42:32 +00:00
|
|
|
*/
|
|
|
|
|
package weak
|