Luis

Thanks for you comments. I agree the limit for 'i' should be defined by the 
length of the smaller array.

However in the loop, 'i' is always less than p.LineCount and p.LineCount 
would never be more than the array size.

I could have used 
if p.LineCount = len(p.Offsets)
But >= felt more correct even though p.LineCount is only ever increnented 
by 1.

This code has loads of tests that ensure it's behaviour is correct.

The loop has now been removed and replaced by a 'copy' statement so there 
is no longer a loop of my ow making. 

I did not use 'append' in the end because I wanted to control the growth of 
the array. It's function is very specific and I wanted to optomise the 
performance myself.

regards

Stuart

On Tuesday, 15 October 2019 11:16:35 UTC+1, 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. 
>
> 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 p.LineCount >= len(p.Offsets) {
>     newLen := p.LineCount + 50
>     sb := make([]int64, newLen)
>     for i := 0; i < p.LineCount; i++ {
>         sb[i] = p.Offsets[i]
>     }
>     p.Offsets = sb
> }
>
> I know there must be an array copy function that will do this more 
> efficiently but I failed to find it!
>
> Please help.
>
>
>

-- 
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/cba53e94-e837-4434-9f4f-47f3b404ae44%40googlegroups.com.

Reply via email to