Is there a way to improve this performance of this further?

Is there a faster/more efficient way to allocate memory for a slice of int64s?

r := make([]int64, 0, 90000)

In Kotlin, an array of longs can be initialized twice as fast as the above code and I was hoping to making the Go version faster.

var result = LongArray(90000)

Here is the code for what I’m trying to do:

I’ve made lots of progress on this, and got a pointer going in and the generate function is mutating the array at the pointer address. This exercise as really helped understand Go further. Is there any way to improve this further?


you are only declaring the variable and no memory has been allocated. If you print len® got 0 because the slice does not have no elements. Now you can generate, say, 90000 elements and set to zero you just do r := make([]int64, 90000, 90000)
And this is done very fast!!!


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.