Standard library / go/types

go/types.StdSizes.Sizeof()

Returns storage size in bytes under the model, or a negative value for an oversized type. Expected stdout: '24\n'.

Formal Syntax & Structure

go syntaxgo
func (s *StdSizes) Sizeof(T Type) int64

Parameters & Attributes

NameTypeDescription
TTypeDestination type or interface, or type to inspect.

Return Value

int64

Returns storage size in bytes under the model, or a negative value for an oversized type.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() {  v := &types.StdSizes{WordSize: 8, MaxAlign: 8}  fmt.Println(v.Sizeof(types.NewSlice(types.Typ[types.Int])))}
Go Reference