Standard library / reflect
reflect.Value.Grow()
Ensures a settable slice can append at least n additional elements without allocating; does not change length. Expected stdout: '1 true\n'.
Formal Syntax & Structure
go syntaxgo
func (v Value) Grow(n int)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| n | int | Requested size, length, capacity or growth amount, as specified by the operation. |
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { s := []int{1} v := reflect.ValueOf(&s).Elem() v.Grow(5) fmt.Println(len(s), cap(s) >= 6)}