Re: [go-nuts] Extending an array 'The right way'. Guidence needed!

2019-10-15 Thread Wojciech S. Czarnecki
On Tue, 15 Oct 2019 03:16:35 -0700 (PDT) Stuart Davies wrote: Uh, the important citation got deleted somehow: [...] https://golang.org/ref/spec#Appending_and_copying_slices "If the capacity of s is not large enough to fit the additional values, append allocates a new, sufficiently large

Re: [go-nuts] Extending an array 'The right way'. Guidence needed!

2019-10-15 Thread Wojciech S. Czarnecki
On Tue, 15 Oct 2019 03:16:35 -0700 (PDT) Stuart Davies wrote: > Hi > > I have a slice backed by an array. > > My understanding is that I can extend the slice (append) up to the > capacity of the array. Its good understanding. > Append fails when the backing array indexes are exceeded.

Re: [go-nuts] Extending an array 'The right way'. Guidence needed!

2019-10-15 Thread Jan Mercl
On Tue, Oct 15, 2019 at 12:16 PM Stuart Davies wrote: > I have a slice backed by an array. > > My understanding is that I can extend the slice (append) up to the capacity > of the array. I guess that by 'extend the slice' you mean reslicing. Yes, that can be done while len <= cap. However,

[go-nuts] Extending an array 'The right way'. Guidence needed!

2019-10-15 Thread Stuart Davies
Hi I have a slice backed by an array. My understanding is that I can extend the slice (append) up to the capacity of the array. After that I do not understand the correct procedure. Append fails when the backing array indexes are exceeded. So I have this temporary piece of code: if