gencode icon indicating copy to clipboard operation
gencode copied to clipboard

On the optimization of large slice

Open caibei1 opened this issue 5 years ago • 0 comments

I see that when I convert the slice into a byte array, I traverse it. If you can judge the slice length here, when the slice length is too large, consider using other conversion methods.

for example: arr is a big slice. arr := make([]float32,1000)
header := *(*reflect.SliceHeader)(unsafe.Pointer(&arr)) header.Len = len(arr) * 4 header.Cap = header.Len bytes := ([]byte)(unsafe.Pointer(&header))

caibei1 avatar Jan 18 '21 06:01 caibei1