func main() {
var cs CustomStruct
r := []byte{.......}
err:=proto.Unmarshal(r, &cs)
if err!=nil {
panic(err)
}
}
When I run go build -gcflags="-m" ./...
, I get
moved to heap: CustomStruct
But with a small change, it does not get moved to the heap:
func main() {
var cs *CustomStruct
r := []byte{.......}
err:=proto.Unmarshal(r, cs)
if err!=nil {
panic(err)
}
}
Now when I run the escape-analysis command, it doesn't say that CustomStruct
gets moved to the heap. What exactly is going on, here?