Poking around the golang's net/http I came across this thing.

var (
 bufioReaderPool   sync.Pool
 bufioWriter2kPool sync.Pool
 bufioWriter4kPool sync.Pool
)

...

func newBufioReader(r io.Reader) *bufio.Reader {
 if v := bufioReaderPool.Get(); v != nil {
 br := v.(*bufio.Reader)
 br.Reset(r)
 return br
 }
 // Note: if this reader size is ever changed, update
 // TestHandlerBodyClose's assumptions.
 return bufio.NewReader(r)
}


func putBufioReader(br *bufio.Reader) {
 br.Reset(nil)
 bufioReaderPool.Put(br)
}


github link 
<https://github.com/golang/go/blob/master/src/net/http/server.go#L814-L822>

There seems to be bufioReaderPool variable which is never initialized with 
the sync.Pool's New method. newBufioReader function is using that pool, but 
all the bufio.NewReaders are always being allocated and they are not being 
reused.

What is the intended behaviour here?


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to