From 0a79b2882dcafbfae688c24f65ad8564cb499414 Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Sat, 4 Aug 2018 13:22:45 +0800 Subject: [PATCH] remove buffer pool --- callbacks.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/callbacks.go b/callbacks.go index c56db28..ed11fbe 100644 --- a/callbacks.go +++ b/callbacks.go @@ -29,11 +29,13 @@ const ( NGHTTP2_ERR_DEFERRED = -508 ) +/* var bufPool = &sync.Pool{ New: func() interface{} { return make([]byte, 16*1024) }, } +*/ // onDataSourceReadCallback callback function for libnghttp2 library // want read data from data provider source, @@ -50,15 +52,17 @@ func onDataSourceReadCallback(ptr unsafe.Pointer, streamID C.int, //log.Println("client dp callback, stream not exists") return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE } - //gobuf := make([]byte, int(length)) - _length := int(length) - gobuf := bufPool.Get().([]byte) - if len(gobuf) < _length { - gobuf = make([]byte, _length) - } - defer bufPool.Put(gobuf) + gobuf := make([]byte, int(length)) + /* + _length := int(length) + gobuf := bufPool.Get().([]byte) + if len(gobuf) < _length { + gobuf = make([]byte, _length) + } + defer bufPool.Put(gobuf) + */ - n, err := s.dp.Read(gobuf[:_length]) + n, err := s.dp.Read(gobuf[0:]) if err != nil { if err == io.EOF { //log.Println("onDataSourceReadCallback end")