@@ -9,21 +9,25 @@ import (
9
9
"unsafe"
10
10
)
11
11
12
- // Pinner represents a set of pinned Go objects. An object can be pinned with
12
+ // A Pinner is a set of pinned Go objects. An object can be pinned with
13
13
// the Pin method and all pinned objects of a Pinner can be unpinned with the
14
14
// Unpin method.
15
15
type Pinner struct {
16
16
* pinner
17
17
}
18
18
19
- // Pin a Go object. The object will not be moved or freed by the garbage
20
- // collector until the Unpin method has been called. The pointer to a pinned
19
+ // Pin pins a Go object, preventing it from being moved or freed by the garbage
20
+ // collector until the Unpin method has been called.
21
+ //
22
+ // A pointer to a pinned
21
23
// object can be directly stored in C memory or can be contained in Go memory
22
- // passed to C functions. If the pinned object iftself contains pointers to Go
24
+ // passed to C functions. If the pinned object itself contains pointers to Go
23
25
// objects, these objects must be pinned separately if they are going to be
24
- // accessed from C code. The argument must be a pointer of any type or an
25
- // unsafe.Pointer. It must be a pointer to an object allocated by calling new,
26
- // by taking the address of a composite literal, or by taking the address of a
26
+ // accessed from C code.
27
+ //
28
+ // The argument must be a pointer of any type or an
29
+ // unsafe.Pointer. It must be the result of calling new,
30
+ // taking the address of a composite literal, or taking the address of a
27
31
// local variable. If one of these conditions is not met, Pin will panic.
28
32
func (p * Pinner ) Pin (pointer any ) {
29
33
if p .pinner == nil {
@@ -59,7 +63,7 @@ func (p *Pinner) Pin(pointer any) {
59
63
p .refs = append (p .refs , ptr )
60
64
}
61
65
62
- // Unpin all pinned objects of the Pinner.
66
+ // Unpin unpins all pinned objects of the Pinner.
63
67
func (p * Pinner ) Unpin () {
64
68
p .pinner .unpin ()
65
69
0 commit comments