Documentation ¶
Overview ¶
Package cgoref a way to tell Go to not move a particular variable around in memory. It is not advised to generally use this package, as it may memory fragmentation, high memory usage, and other funky things.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CRef ¶
type CRef struct {
// contains filtered or unexported fields
}
func Ref ¶
Ref will hold a given pointer inside a CGO call until UnRef is called. In Go 1.6, this should prevent Go from moving it around in memory and changing its address until it has been unreffed. This will, of course, completey hose Go's garbage collector's ability to be effective. You may end up with OOMs or very fragmented memory, or other wacky things.
Mostly untested.
Example ¶
buf := make([]byte, 1024) var CThing C.struct_some_thing // Make sure it won't move during processing. ref, err := cgoref.Ref(unsafe.Pointer(&buf[0])) if err != nil { return nil, err } // Stash it in a C struct for multiple uses. Evil! CThing.buf = unsafe.Pointer(&buf[0]) length := int(C.some_init(&CThing)) for i := 0; i < length; i++ { C.some_process(&CThing) } // Hand Go back control. ref.UnRef() return buf, nil
Output:
Click to show internal directories.
Click to hide internal directories.