On Tuesday, June 23, 2020 at 7:32:56 PM UTC-5, Bill Morgan wrote: > > I'm a C programmer so maybe this is a dumb question but, why does this > code in runtime/gostring.go allocate (rawstring) then copy data (memmove) > instead of just making the stringStruct.str point at the incoming data? > i.e. copy the pointer instead of allocating+copying data. > > > func gostring(p *byte) string { > l := findnull(p) > if l == 0 { > return "" > } > s, b := rawstring(l) > memmove(unsafe.Pointer(&b[0]), unsafe.Pointer(p), uintptr(l)) > return s > } >
looks like the code came from commit: 61dca94e107170d2ff3beb13bb9fa5ce49d8d6fd and the old string.c file had a gostringnocopy that copied the ptr instead of allocating and copying. Wondering why that was removed. I guess there must be some reason that you must have a duplicate copy. -- 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/5b23933b-5d8b-425a-85ea-6042069a661bo%40googlegroups.com.