func NewBytePool() BytePool {
	return BytePool{
		tinySlab:   newByteSlab(tiny, tinyCount),
		smallSlab:  newByteSlab(small, smallCount),
		mediumSlab: newByteSlab(medium, mediumCount),
		largeSlab:  newByteSlab(large, largeCount),
		hugeSlab:   newByteSlab(huge, hugeCount),
	}
}
NewBytePool creates a new BytePool with each slab using 1 MB of storage.
The pool contains 5 slabs of different sizes: 64B, 512B, 1KB, 10KB and 100KB.
Allocations above 100KB will be allocated directly.
package tcontainer
import (
	"reflect"
	"runtime"
	"sync/atomic"
	"unsafe"
)
const (
	tiny   = 64
	small  = 512
	medium = 1024
	large  = 1024 * 10
	huge   = 1024 * 100
	tinyCount   = 16384  
	smallCount  = 2048   
	mediumCount = 1024   
	largeCount  = 102    
	hugeCount   = 10     
)
type byteSlab struct {
	buffer     []byte
	bufferSize uintptr
	stride     uintptr
	basePtr    *uintptr
	nextPtr    *uintptr
}
type BytePool struct {
	tinySlab   byteSlab
	smallSlab  byteSlab
	mediumSlab byteSlab
	largeSlab  byteSlab
	hugeSlab   byteSlab
}
func newByteSlab(size, count int) byteSlab {
	bufferSize := count * size
	buffer := make([]byte, bufferSize)
	basePtr := (*reflect.SliceHeader)(unsafe.Pointer(&buffer)).Data
	nextPtr := basePtr + uintptr(bufferSize)
	return byteSlab{
		buffer:     buffer,
		bufferSize: uintptr(bufferSize),
		stride:     uintptr(size),
		basePtr:    &basePtr,
		nextPtr:    &nextPtr,
	}
}
func (slab *byteSlab) getSlice(size int) (chunk []byte) {
	chunkHeader := (*reflect.SliceHeader)(unsafe.Pointer(&chunk))
	chunkHeader.Len = size
	chunkHeader.Cap = int(slab.stride)
	for {
		basePtr := atomic.LoadUintptr(slab.basePtr)
		nextPtr := atomic.AddUintptr(slab.nextPtr, -slab.stride)
		lastPtr := basePtr + slab.bufferSize
		switch {
		case nextPtr < basePtr || nextPtr >= lastPtr:
			runtime.Gosched()
		case nextPtr == basePtr:
			slab.buffer = make([]byte, slab.bufferSize)
			dataPtr := (*reflect.SliceHeader)(unsafe.Pointer(&slab.buffer)).Data
			atomic.StoreUintptr(slab.nextPtr, dataPtr+slab.bufferSize)
			atomic.StoreUintptr(slab.basePtr, dataPtr)
			fallthrough
		default:
			chunkHeader.Data = nextPtr
			return
		}
	}
}