github.com/lemon-mint/libuseful@v1.3.1-0.20220724073654-ee73785d5aa0/example/memmove/mem.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"reflect"
     6  	"unsafe"
     7  
     8  	"github.com/lemon-mint/libuseful"
     9  )
    10  
    11  func main() {
    12  	var a = []byte{
    13  		0, 1, 2, 3,
    14  	}
    15  	var b = []byte{
    16  		0, 0, 0, 0,
    17  	}
    18  
    19  	A := (*reflect.SliceHeader)(unsafe.Pointer(&a))
    20  	B := (*reflect.SliceHeader)(unsafe.Pointer(&b))
    21  
    22  	fmt.Println("A:", a)
    23  	fmt.Println("B:", b)
    24  	libuseful.MemMove(unsafe.Pointer(B.Data), unsafe.Pointer(A.Data), 4)
    25  	fmt.Println("libuseful.MemMove(B, A, 4)")
    26  	fmt.Println("A:", a)
    27  	fmt.Println("B:", b)
    28  }