// assume that arr is a slice of integers.for index, _ := range arr {arr[index] = 0}Is there an alternative to the above code?
-Kowshik--
Hi,
I am not very knowledgeable in that area, but wouldn't the copy-based version be more amenable to compiler optimization (think simd, avx,...) than the for-loop one ?
-s
-- sent from my droid --
--
It's probably more accurate to think of copy(s, make([]int, len(s))) as just s = make([]int, len(s)). The loop changes the values of an existing array to 0.
--
But you're still allocating a new array, right?