Skip to content

Instantly share code, notes, and snippets.

@sylr
Created March 5, 2020 17:01
Show Gist options
  • Select an option

  • Save sylr/ffaf2c44fc4b3f9198d6595b49736dcb to your computer and use it in GitHub Desktop.

Select an option

Save sylr/ffaf2c44fc4b3f9198d6595b49736dcb to your computer and use it in GitHub Desktop.
inheap
package main
import (
_ "unsafe"
"fmt"
)
var slice = []byte("AAA")
func main() {
buf := make([]byte, 0, 6)
buf = append(buf, slice...)
fmt.Println("is buf in heap?", inheap(&buf[0]))
buf2 := make([]byte, 0, len(slice))
buf2 = append(buf2, slice...)
fmt.Println("is buf2 in heap?", inheap(&buf2[0]))
}
//go:linkname inheap runtime.inheap
//go:noescape
func inheap(ptr *byte) bool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment