unsafe基本用法

unsafe基本用法

合理的用法 #

// The cases is suitable for unsafe
type MyInt int

//合理的类型转换
func TestConvert(t *testing.T) {
        a := []int{1, 2, 3, 4}
        b := *(*[]MyInt)(unsafe.Pointer(&a))
        t.Log(b)
}

From #