On Sat, Oct 12, 2019 at 1:47 AM tokers <zchao1...@gmail.com> wrote: > > Recently I read some go source code and when I read the noescape function in > runtime/stubs.go, I have a doubt about it. > > // noescape hides a pointer from escape analysis. noescape is > // the identity function but escape analysis doesn't think the > // output depends on the input. noescape is inlined and currently > // compiles down to zero instructions. > // USE CAREFULLY! > //go:nosplit > func noescape(p unsafe.Pointer) unsafe.Pointer { > x := uintptr(p) > return unsafe.Pointer(x ^ 0) > } > > > > I don't know what's the purpose of the exclusive or operation? Does it > necessary?
The function comment seems clear. Can you be more specific about your question? This is necessary because sometimes the runtime needs to not allocate a value that would otherwise be allocated. For example, the runtime includes the implementation of the heap allocator, and clearly that implementation cannot itself allocate anything. The noescape function is used where allocation would otherwise occur, to ensure that it does not actually allocate. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXf9mUbXfHrOa%2BmORh0pZ%3DOGmKsRsE8edze%2B19tcWh_kA%40mail.gmail.com.