Documentation
¶
Overview ¶
Package reflectx provides reflection-based helpers that extend the standard library reflect package, such as estimating the in-memory payload of a value.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrFailEstimatePayload = -1
ErrFailEstimatePayload is returned by EstimatePayloadOf when the payload size cannot be determined.
Functions ¶
func EstimatePayloadOf ¶
EstimatePayloadOf returns an approximate payload size (in bytes) of the given value.
This function performs **zero allocations** and runs with **0 B/op**.
Supported types:
- all scalar types and their pointers: int, int8, int16, int32 (rune), int64, uint, uint8 (byte), uint16, uint32, uint64, uintptr, float32, float64, complex64, complex128, bool, string, time.Time, time.Duration
- slices of the above types and their pointers: []T, *[]T, []*T, *[]*T
- arrays [N]T and *[N]T (via reflection)
For pointer and slice values, nil is treated as zero size. For strings and slices of strings, the sum of actual string lengths is returned.
If the type is not recognized or cannot be handled, the function returns ErrFailEstimatePayload.
Performance note:
For arrays [N]T it is highly recommended to pass a pointer (*[N]T) instead of the array value itself. Passing an array by value causes the entire array to be copied when calling this function, which can make estimation dozens or even hundreds of times slower for large arrays.
Types ¶
This section is empty.