github.com/webmafia/fast@v0.10.0/make.go (about) 1 package fast 2 3 import ( 4 _ "runtime" 5 "unsafe" 6 ) 7 8 // MakeNoZero makes a slice of length and capacity l without zeroing the bytes. 9 // It is the caller's responsibility to ensure uninitialized bytes 10 // do not leak to the end user. 11 func MakeNoZero(l int) []byte { 12 return unsafe.Slice((*byte)(mallocgc(uintptr(l), nil, false)), l) 13 } 14 15 // MakeNoZero makes a slice of length l and capacity c without zeroing the bytes. 16 // It is the caller's responsibility to ensure uninitialized bytes 17 // do not leak to the end user. 18 func MakeNoZeroCap(l int, c int) []byte { 19 return MakeNoZero(c)[:l] 20 } 21 22 //go:linkname mallocgc runtime.mallocgc 23 func mallocgc(size uintptr, typ unsafe.Pointer, needzero bool) unsafe.Pointer