The method you described creates a slice of slices that looks like the 2d array you want. I suggest you change the type to uint8, since you will be interested in only 3 states of nothing / first / second player.
This selects each line separately (in your tests you will see at least m + 1 allocs/op ). This is not very pleasant, because there is no guarantee that individual distributions will be localized close to each other.
To save the location, you can do something like this:
M := make([][]uint8, row) e := make([]uint8, row * col) for i := range M { a[i] = e[i * col:(i + 1) * col] }
This will end up with only 2 distributions, and the slice slice will maintain data locality. Please note that you can still access your M in the format 2d M[2][6] .
A good video that explains how to do it even faster.
Salvador dali
source share