I have two byte buffers var a,b []byte
, I am looking for a replacement for Go's built-in copy function to copy from one byte buffer to the other, preferably pure Go implementation and efficiency is important.
The reason is that copy
reliably crashes my program due to unexpected fault address
, therefore I would like to experiment with a non-native copy()
replacement to find out if the crash was caused by my program logics or not.
For the sake of debugging, use something like this:
func myCopy (a, b []byte) int {
var length int
if (len(a) < len(b)) {
length = len(a)
} else {
length = len(b)
}
for i := 0; i < length; i++ {
a[i] = b[i]
}
return length
}