Correctly manage partial writes

This commit is contained in:
9seconds
2021-03-29 10:26:52 +03:00
parent db8614999a
commit 3992054560
7 changed files with 75 additions and 38 deletions
+25 -6
View File
@@ -1,12 +1,22 @@
package record
import "sync"
import (
"bytes"
"sync"
)
var recordPool = sync.Pool{
New: func() interface{} {
return &Record{}
},
}
var (
recordPool = sync.Pool{
New: func() interface{} {
return &Record{}
},
}
bytesBufferPool = sync.Pool{
New: func() interface{} {
return &bytes.Buffer{}
},
}
)
func AcquireRecord() *Record {
return recordPool.Get().(*Record)
@@ -16,3 +26,12 @@ func ReleaseRecord(r *Record) {
r.Reset()
recordPool.Put(r)
}
func acquireBytesBuffer() *bytes.Buffer {
return bytesBufferPool.Get().(*bytes.Buffer)
}
func releaseBytesBuffer(buf *bytes.Buffer) {
buf.Reset()
bytesBufferPool.Put(buf)
}