Standard library / unsafe

unsafe.Sizeof()

Reports the storage size of a variable of the expression’s type, including struct padding but excluding referenced allocations. A fixed-size type yields a constant and its operand is not evaluated. For type parameters the result is not generally constant. Use len for element counts. Signatures use documentation-only placeholders where applicable; these are compiler intrinsics, not ordinary function values. Expected stdout: '4\ntrue\n'.

Formal Syntax & Structure

go syntaxgo
func Sizeof(x ArbitraryType) uintptr

Parameters & Attributes

NameTypeDescription
xArbitraryTypeExpression of the type whose storage size is measured.

Return Value

uintptr

Storage size in bytes; may depend on architecture.

Working Example

Example Snippetgo
package main
import (  "fmt"  "unsafe")
func main() {  var n uint32  data := make([]byte, 100)  fmt.Println(unsafe.Sizeof(n))  fmt.Println(unsafe.Sizeof(data) == 3*unsafe.Sizeof(uintptr(0)))}
Go Reference