Package unsafe contains operations that step around the type safety of Go programs.
Packages that import unsafe may be non-portable and are not protected by the Go 1 compatibility guidelines.
In the call graph viewer below, each node is a function belonging to this package and its children are the functions it calls—perhaps dynamically.
The root nodes are the entry points of the package: functions that may be called from outside the package. There may be non-exported or anonymous functions among them if they are called dynamically from another package.
Click a node to visit that function's source code.
From there you can visit its callers by
clicking its declaring
Functions may be omitted if they were determined to be unreachable in the particular programs or tests that were analyzed.
func Alignof(x ArbitraryType) uintptr
Alignof takes an expression x of any type and returns the alignment of a hypothetical variable v as if v was declared via var v = x. It is the largest value m such that the address of v is zero mod m.
func Offsetof(x ArbitraryType) uintptr
Offsetof returns the offset within the struct of the field represented by x, which must be of the form structValue.field. In other words, it returns the number of bytes between the start of the struct and the start of the field.
func Sizeof(x ArbitraryType) uintptr
Sizeof takes an expression x of any type and returns the size in bytes of a hypothetical variable v as if v was declared via var v = x. The size does not include any memory possibly referenced by x. For instance, if x is a slice, Sizeof returns the size of the slice descriptor, not the size of the memory referenced by the slice.
type ArbitraryType int
ArbitraryType is here for the purposes of documentation only and is not actually part of the unsafe package. It represents the type of an arbitrary Go expression.
type Pointer *ArbitraryType
Pointer represents a pointer to an arbitrary type. There are four special operations available for type Pointer that are not available for other types.
1) A pointer value of any type can be converted to a Pointer. 2) A Pointer can be converted to a pointer value of any type. 3) A uintptr can be converted to a Pointer. 4) A Pointer can be converted to a uintptr.
Pointer therefore allows a program to defeat the type system and read and write arbitrary memory. It should be used with extreme care.