A multi level memory pool for Golang:
The design thoughts are detailed in golang multi-level memory pool design and implemention(in Chinese🇨🇳).
go get github.com/liudanking/gmmpool
package main
import (
"bytes"
"log"
"github.com/liudanking/gmmpool"
)
func main() {
pool := gmmpool.NewMultiLevelPool([]gmmpool.PoolOpt{
gmmpool.PoolOpt{Num: 10, Size: 1024}, // level 0
gmmpool.PoolOpt{Num: 10, Size: 1024 * 2}, // level 1
})
buf := pool.Get(1025)
defer pool.Put(buf)
data, err := buf.ReadAll(bytes.NewReader(make([]byte, 8)))
if err != nil {
log.Fatal(err)
}
log.Print(data)
}
BenchmarkStdReadAll-4 200000 5969 ns/op
BenchmarkMultiLevelPool-4 5000000 311 ns/op