I don't understand something when I want to pop out first element of a 
slice and use it.
Here is my version:
s := []int{1,2,3}
first := s[0]
s = s[1:]

Here is a version that I saw in the standard library: 
first := s[0]
copy(s, s[1:])
s = s[:len(s) - 1]

I wonder, why do we need to translate the other elements to the left with a 
copy ? 
In the first case, I guess the first element will still be found in the 
underlying array, and in the second case the last element.
It's not like for avoiding a memory leak, because neither version allocates 
a new underlying array.

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.

Reply via email to