> On Jun 26, 2024, at 2:46 AM, Axel Wagner <axel.wagner...@googlemail.com> > wrote: > > It is defined in the runtime and go:linkname'd into the bytealg package: > https://github.com/golang/go/blob/90bcc552c0347948166817a602f612f219bc980c/src/runtime/slice.go#L394 > > <https://github.com/golang/go/blob/90bcc552c0347948166817a602f612f219bc980c/src/runtime/slice.go#L394> Thank you for that link.
> On Jun 26, 2024, at 2:54 AM, Axel Wagner <axel.wagner...@googlemail.com> > wrote: > > And in terms of practical advice: > > You might be able to use go:linkname yourself to get access to that > functionality from the runtime. But note that go:linkname is being locked > down in Go 1.23 <https://github.com/golang/go/issues/67401>, so that is not a > future-proof plan. > > Your best bet is probably to file a proposal to get the functionality you > want for strings.Builder. Or to get an exported API (say in the runtime > package) to allocate non-zeroed memory. My email to the list was actually my precursor research for exactly that; to submit a proposal to add Rewind() to strings.Builder{}. My proposal will elaborate on a common use-case where I would see the need for that functionality along with a mention about the alternate being to use go:linkname. Then I might mention the proposal on that thread about locking down go:linkname. :-) > Otherwise, you might be able to use `unsafe` to access the unexported fields > of `strings.Builder`. That is, you can define your type as > type MyBuilder struct { > strings.Builder > } > and then add methods to that which use `unsafe` to do what you want. Though > that will, of course, also be dangerous and should be guarded with build tags > for the used Go version, at the least. Nah, do not want to do that. But thank you for elaborating in case I did. -Mike -- 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/0B47CAF5-C964-43BB-B789-1BABE1A67BCD%40newclarity.net.