Skip to content

Commit

Permalink
3rd - bytebufferpool
Browse files Browse the repository at this point in the history
  • Loading branch information
darjun committed May 8, 2021
1 parent f32ec5f commit 61a4986
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -113,4 +113,6 @@
* [goquery](https://darjun.github.io/2020/10/11/godailylib/goquery)
Go 的**jQuery**
* [rxgo](https://darjun.github.io/2020/10/11/godailylib/rxgo)
基于[pipelines](https://blog.golang.org/pipelines)的异步编程库。
基于[pipelines](https://blog.golang.org/pipelines)的异步编程库。
* [bytebufferpool](https://darjun.github.io/2021/05/08/godailylib/bytebufferpool)
基于`sync.Pool`实现的高性能对象缓冲池。
18 changes: 18 additions & 0 deletions bytebufferpool/get-started/main.go
@@ -0,0 +1,18 @@
package main

import (
"fmt"

"github.com/valyala/bytebufferpool"
)

func main() {
b := bytebufferpool.Get()
b.WriteString("hello")
b.WriteByte(',')
b.WriteString(" world!")

fmt.Println(b.String())

bytebufferpool.Put(b)
}
5 changes: 5 additions & 0 deletions bytebufferpool/go.mod
@@ -0,0 +1,5 @@
module github.com/darjun/go-daily-lib/bytebufferpool

go 1.16

require github.com/valyala/bytebufferpool v1.0.0 // indirect
2 changes: 2 additions & 0 deletions bytebufferpool/go.sum
@@ -0,0 +1,2 @@
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
19 changes: 19 additions & 0 deletions bytebufferpool/new-pool/main.go
@@ -0,0 +1,19 @@
package main

import (
"fmt"

"github.com/valyala/bytebufferpool"
)

func main() {
joinPool := new(bytebufferpool.Pool)
b := joinPool.Get()
b.WriteString("hello")
b.WriteByte(',')
b.WriteString(" world!")

fmt.Println(b.String())

joinPool.Put(b)
}

0 comments on commit 61a4986

Please sign in to comment.