On Tue, 18 Apr 2017, at 03:20 PM, Chris Hopkins wrote:
> I'm not sure what you mean by the append doesn't modify the original. > Append will use the same backing store (if there is available capacity > in it) and by definition the address of the slice in question must be > invariant across its context. e.g.: > https://play.golang.org/p/lBRpKSo-9P > I think of a slice as a built in structure so the pointer to the > backing store will stay the same, the capacity will stay the same, > only the length will change with append. (unless there is insufficient > capacity then all bets are off except that again the original > structure will remain, but all the values in it will be overwritten, > then copied back into the original struct) > > Or have I really misunderstood what happens under the hood here? The backing store is reused if there is capacity but append returns a new slice that points to it. A small modification to your code demonstrates it: https://play.golang.org/p/ov5aerw-Wp Ian -- 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.