4 ms·
> Whether you create multiple views in the array, mutate the views Whether there are multiple views or not is actually an implementation detail, and whether "a
by TheDong 8y ago
> Whether you create multiple views in the array, mutate the views
Whether there are multiple views or not is actually an implementation detail, and whether "append" chooses to allocate memory or not will change whether there are multiple copies or multiple views of the array.
All of that behavior is something you absolutely cannot rely on.
- kodablah 8y agoCan I not rely on append only allocating when the values to append won't fit in the remaining capacity of the underlying array starting from the end of the slice? Some articles indicate this and definitely don't seem surprising [0]. Granted I don't know the implementation details, but how do copies of the array or numbers of slices of the array affect that? Regardless, with Go as opposed to lower level languages, building reliance on whether functions do memory allocation (even built in ones) is folly. 0 - https://blog.golang.org/go-slices-usage-and-internals https://blog.golang.org/go-slices-usage-and-internals
- slrz 8y agoThe behaviour of append and the conditions where it will allocate a new backing array are specified and part of the language. Implementation details don't even enter the picture here. You can absolutely rely on that not changing.