Yes, we can't depend on the data at *p to remain constant. We need to 
snapshot it at the moment of the gostring call.

On Tuesday, June 23, 2020 at 5:52:23 PM UTC-7, Kurtis Rader wrote:
>
> On Tue, Jun 23, 2020 at 5:32 PM Bill Morgan <arthurwil...@gmail.com 
> <javascript:>> 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.
>>
>
> Go strings are immutable: https://golang.org/ref/spec#String_types.
>
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
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/67d83906-f6ac-4457-bb34-fb3cc1716197o%40googlegroups.com.

Reply via email to