Documentation
¶
Index ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Sizable ¶
type Sizable interface {
// SizeOf returns the size of this entity.
SizeOf() Size
}
Sizable is an interface describing a type that may have its runtime memory resident size estimated.
type Size ¶
type Size uintptr
func Of ¶
Of returns the size of an object. When the input is a pointer to an object, the size of the pointer itself is returned, as opposed to the size of the memory referenced. This function cannot infer the data type of nil, so nil checks need to be performed before calling this function.
func OfAny ¶
OfAny attempts to return the size of a value passed as `any`. This is done via type negotiation to unwrap the `any` type in a best-effort attempt to estimate the value's size.
It is important to note that this function comes with usage caveats: * Maps are not estimated by this function * Nested slices of type `[]any` are supported but have ill-defined runtime measurement costs * If the type of the value is known, this function is less performant that calling Of(...)
func OfAnySlice ¶
OfAnySlice calculates the estimated size of a given slice of type `[]any`.
func OfSlice ¶
func OfSlice[T comparable](sliceT []T) Size
OfSlice will return the size of a type templated slice.
The slice descriptor consists of three fields: * A pointer to the underlying array. * The length of the slice (the number of elements currently in use). * The capacity of the slice (the total number of elements in the underlying array, from the start of the slice).
On a 64-bit architecture, each of these fields is 8 bytes, so the size of a slice is 24 bytes. On a 32-bit architecture, each field is 4 bytes, making the slice size 12 bytes. The unsafe.Sizeof() function will return this size of the descriptor, not the size of the underlying array.
For correctly typed templates the capacity of the slice is multiplied by the size of the template.