Documentation
¶
Index ¶
- func Alignof[ArbitraryType _ArbitraryType](x ArbitraryType) uintptr
- func F[F interface{ ... }](f F, typ ...Type) field
- func Field[F interface{ ... }](f F, typ ...Type) field
- func FindPointerFields(t reflect.Type) []pointers
- func Malloc(size uintptr, zero bool, t ...reflect.Type) unsafe.Pointer
- func New[T any](fp ...[]pointers) *T
- func SetZeros(baseAddress unsafe.Pointer, offset, size uintptr)
- func Sizeof[ArbitraryType _ArbitraryType](x ArbitraryType) uintptr
- func Slice[ArbitraryType _ArbitraryType, IntegerType _IntegerType](ptr *ArbitraryType, len IntegerType) []ArbitraryType
- func SliceData[ArbitraryType _ArbitraryType](slice []ArbitraryType) *ArbitraryType
- func String[IntegerType _IntegerType](ptr *byte, len IntegerType) string
- func StringData(str string) *byte
- func Value[T any](strct any, f field) T
- type Pointer
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Field ¶
Field selects a field in a struct. The field can be selected by passing an integer or a (name) string. An optional type constraint can be provided as a safety precaution to ensure that the field's type is what you expected.
func FindPointerFields ¶ added in v1.2.0
FindPointerFields finds the offsets of all fields in a struct that contain pointers and other reference types.
func Malloc ¶ added in v1.2.0
Malloc allocates contiguous blocks of memory without zeroing the values. All allocated memory must immediately be filled by the developer, since the pre-existing data may contain garbage.
Warning: If the returned pointer will be cast to a struct with fields that contain pointers, then provide a reflect Type for that struct. See: https://github.com/golang/go/issues/76352#issuecomment-3549768452
Example:
type Person struct {
name string
age int
phone *int
}
ptr := Malloc(unsafe.Sizeof(Person{}), false, reflect.TypeFor[Person]())
p := *(*Person)(ptr)
func New ¶ added in v1.2.0
func New[T any](fp ...[]pointers) *T
New allocates memory for a struct. The value returned is a pointer to a newly allocated value of that type. The returned struct is not guaranteed to be the zero value.
func SetZeros ¶ added in v1.2.0
SetZeros sets memory address located at (baseAddress + offset) to zero. Size (in bytes) dictates how many contiguous locations to set to zero. No bytes are set to zero if size is 0.
func Slice ¶
func Slice[ArbitraryType _ArbitraryType, IntegerType _IntegerType](ptr *ArbitraryType, len IntegerType) []ArbitraryType
Slice
func SliceData ¶
func SliceData[ArbitraryType _ArbitraryType](slice []ArbitraryType) *ArbitraryType
SliceData
func StringData ¶
StringData
Types ¶
type Pointer ¶
Pointer