github.com/iikira/iikira-go-utils@v0.0.0-20230610031953-f2cb11cde33a/utils/cachepool/malloc_test.go (about) 1 package cachepool_test 2 3 import ( 4 "fmt" 5 "github.com/iikira/iikira-go-utils/utils/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 }