github.com/fzfile/BaiduPCS-Go@v0.0.0-20200606205115-4408961cf336/pcsutil/cachepool/malloc_test.go (about) 1 package cachepool_test 2 3 import ( 4 "fmt" 5 "github.com/fzfile/BaiduPCS-Go/pcsutil/cachepool" 6 "reflect" 7 "runtime" 8 "testing" 9 "unsafe" 10 ) 11 12 func TestMalloc(t *testing.T) { 13 b := cachepool.RawMallocByteSlice(128) 14 for k := range b { 15 b[k] = byte(k) 16 } 17 fmt.Println(b) 18 runtime.GC() 19 20 b = cachepool.RawMallocByteSlice(128) 21 fmt.Printf("---%s---\n", b) 22 runtime.GC() 23 24 b = cachepool.RawByteSlice(128) 25 fmt.Println(b) 26 runtime.GC() 27 28 b = cachepool.RawByteSlice(127) 29 bH := (*reflect.SliceHeader)(unsafe.Pointer(&b)) 30 fmt.Printf("%#v\n", bH) 31 }