Thanks.

The copy command was the thing I missed. It does exactly what I need and I 
can control the extension of the backing array with fine detail.

I assume the copy command is implemented efficiently but even if it just 
loops it is a packaged process and will have been optomised by the Go devs 
so it is as good as I am likly to get.

Thanks all for your help :-)

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/f9d99d10-fca2-48c7-ae83-f42595206dbd%40googlegroups.com.

Reply via email to