sizeof

package
v0.0.0-...-59766ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2025 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package sizeof provides utility functions for recursively computing the size of Go objects in memory, using the reflect package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepSize

func DeepSize(v interface{}) int64

DeepSize reports the size of v in bytes, as reflect.Size, but also including all recursive substructures of v via maps, pointers, and slices. If v contains any cycles, the size of each pointer (re)introducing the cycle is included but the acyclic substructure is counted only once.

Only values whose size and structure can be obtained by the reflect package are counted. Some values have components that are not visible by reflection, and so are not counted or may be undercounted. In particular:

The space occupied by code and data, reachable through variables captured in the closure of a function pointer, are not counted. A value of function type is counted only as a pointer.

The unused buckets of a map cannot be inspected by the reflect package. Their size is estimated by assuming unfilled slots contain zeroes of their type.

The unused capacity of the array under a slice is estimated by assuming the unused slots contain zeroes of their type. It is possible they contain non zero values from sharing or reslicing, but without explicitly reslicing the reflect package cannot touch them.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL