Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Change to use a pool of byte buffer to encode data
- Loading branch information
1 parent
e0f40b1
commit d0cdf96
Showing
3 changed files
with
61 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package fluent | ||
|
||
import ( | ||
"bytes" | ||
"sync" | ||
) | ||
|
||
type Message struct { | ||
buf *bytes.Buffer | ||
} | ||
|
||
var messagePool = sync.Pool{ | ||
New: func() interface{} { | ||
return newMessage() | ||
}, | ||
} | ||
|
||
func getMessage() *Message { | ||
message := messagePool.Get().(*Message) | ||
message.buf.Reset() | ||
return message | ||
} | ||
|
||
func putMessage(message *Message) { | ||
messagePool.Put(message) | ||
} | ||
|
||
func newMessage() *Message { | ||
return &Message{ | ||
buf: bytes.NewBuffer([]byte{}), | ||
} | ||
} |