Standard library / reflect
reflect.SliceAt()
Creates a slice view over existing storage at a pointer, with length and capacity n. Caller must ensure alignment, lifetime and enough contiguous elements; this is not a bounds-checking allocator. Expected stdout: '[1 8 3]\n'.
Formal Syntax & Structure
go syntaxgo
func SliceAt(typ Type, p unsafe.Pointer, n int) ValueParameters & Attributes
| Name | Type | Description |
|---|---|---|
| typ | Type | Runtime type descriptor for the new value. |
| p | unsafe.Pointer | Pointer to live, correctly aligned storage matching the element type. |
| n | int | Requested size, length, capacity or growth amount, as specified by the operation. |
Return Value
Value
Creates a slice view over existing storage at a pointer, with length and capacity n.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect" "unsafe")
func main() { a := [3]int{1, 2, 3} v := reflect.SliceAt(reflect.TypeFor[int](), unsafe.Pointer(&a[0]), len(a)) v.Index(1).SetInt(8) fmt.Println(a)}