That trick was copied from 
here: 
https://cs.opensource.google/go/go/+/refs/tags/go1.19:src/strings/builder.go;l=26

See https://github.com/golang/go/issues/23382 
and https://github.com/golang/go/issues/23382 
and https://github.com/golang/go/issues/7921

I don't know why the trick works in your case.  It appears to be safe.
On Wednesday, August 24, 2022 at 2:59:34 AM UTC-4 mozart...@gmail.com wrote:

> I was try using net.Buffers for writev. But I meet a unexptected allocs in 
> benchmark.  
>
> https://go.dev/play/p/SHpxSYbP1I5
>
> when I run the benchmark:
>
> goos: linux
> goarch: amd64
> pkg: writev
> BenchmarkWrite_Writev/escape-4               272901          4198 ns/op   
>        24 B/op           1 allocs/op
> BenchmarkWrite_Writev/noescape-4             273751          4267 ns/op   
>         0 B/op           0 allocs/op
> PASS
> ok      writev    3.410s
>
> Is the noescape safe ? 
> Is there a better way to avoid the alloc/escape ?
> -
> Best regards
> Lee
>

-- 
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/dfee8e9c-3387-4838-9ac5-077828a9f2a3n%40googlegroups.com.

Reply via email to