On Tue, Aug 28, 2018 at 4:55 PM Jay Sharma <jaysharma...@gmail.com> wrote:
> As I am overwriting the content with new content, Is it inplace replacement [same memory is being updated] or a new copy will be created with new content and old content will be there in the memory ? Basically none of that. Strings indeed are immutable. Consider s := "foo" t := s s := "bar" After this t == "foo" is still true. The implementation of this is that a mutable _variable_ of type string internally points to an immutable string _value_ (in the first approximation). So assigning(copying) the 's' variable makes 't' have the value "foo" and keeps it even if the variable 's' is later mutated to point to a different string value. The concept extends to any RHS string expression assignment, not only 's'. The LHS (or the pointee in p := &t; *pt := whatever) is mutable independently of the immutable value it represents (provides, points to). The nice side effect is that every string variable is unique, but the string values they represent may be shared without copying the actual string value - only the string variable is ever copied. And that's an O(1) thing. -- -j -- 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. For more options, visit https://groups.google.com/d/optout.