Documentation
¶
Overview ¶
Package memsize provides utilities to estimate the memory footprint of Go values without relying on the reflect or unsafe packages for direct memory inspection.
It leverages the gob encoding mechanism to serialize values into memory buffers and calculate their approximate in-memory size in bytes.
This approach prioritizes safety and portability over raw performance, making it suitable for debugging, profiling, or logging approximate memory usage of application data structures.
Features:
- Estimate the size of any Go value in bytes using gob encoding.
- Human-readable byte formatting with SI units (e.g., "1.2 kB").
- Graceful handling of nil pointers, maps, slices, arrays, and channels.
Example:
size, err := memsize.SizeOf(myStruct)
if err != nil {
log.Fatal(err)
}
fmt.Println("Memory size:", memsize.ToByteString(size))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InterfaceIsNullPointer ¶
func InterfaceIsNullPointer(i interface{}) bool
InterfaceIsNullPointer returns true if the interface is nil or if the interface is a pointer, map, chan, or slice and is nil
func SizeOf ¶
SizeOf returns the number of bytes that 'value' takes up in memory, without using reflect or unsafe this functions has minor overhead for the encoding process.
func ToByteString ¶
ToByteString returns the number of bytes as a string with a unit
Types ¶
This section is empty.