|
|
|
|
|
by ernst_klim
2882 days ago
|
|
Both arrays and interfaces are heap allocated. Slice is just a pointer to a heap allocated array. Structure could be stack allocated, but any of it's fields would not if there is anything but a number. A trivial example: https://segment.com/blog/allocation-efficiency-in-high-perfo... func main() {
x := 42
fmt.Println(x)
}
./main.go:7: x escapes to heap
So a trivial interface cast leads to allocation. |
|