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

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"unsafe"
     6  
     7  	"github.com/lemon-mint/libuseful"
     8  )
     9  
    10  func main() {
    11  	var a int64 = 2048
    12  	var AllocStat libuseful.SysMemStat
    13  
    14  	fmt.Println("AllocStat:", AllocStat)
    15  
    16  	ptr := libuseful.SysAlloc(8, &AllocStat)
    17  
    18  	fmt.Println("AllocStat:", AllocStat)
    19  	fmt.Println(*(*int)(ptr))
    20  	libuseful.MemMove(ptr, unsafe.Pointer(&a), 8)
    21  	fmt.Println(*(*int)(ptr))
    22  
    23  	libuseful.SysFree(ptr, 8, &AllocStat)
    24  
    25  	fmt.Println("AllocStat:", AllocStat)
    26  
    27  }