1
0
mirror of https://github.com/fumiama/orbyte.git synced 2026-06-10 13:10:32 +08:00

feat(pbuf): add USRDAT

This commit is contained in:
源文雨
2025-02-26 16:35:01 +09:00
parent 72938b1e5f
commit 8c0982b885
7 changed files with 105 additions and 62 deletions

View File

@@ -3,16 +3,27 @@ Lightweight & Safe (buffer-writer | general object) pool.
## Quick Start
```go
import (
"crypto/rand"
package main
"github.com/fumiama/orbyte/pbuf"
import (
"crypto/rand"
"io"
"github.com/fumiama/orbyte/pbuf"
)
func main() {
b := pbuf.NewBytes(1024) // Allocate Bytes from pool.
rand.Read(b.Bytes()) // Do sth.
b.KeepAlive() // Mark as reachable.
// After that, b will be auto-reused on GC.
buf := pbuf.NewBuffer(nil) // Allocate Buffer from pool.
buf.P(func(buf *pbuf.Buffer) {
io.CopyN(buf, rand.Reader, 4096) // Do sth.
})
// After that, buf will be auto-reused on GC.
b := pbuf.NewBytes(1024) // Allocate Bytes from pool.
b.V(func(b []byte) {
rand.Read(b) // Do sth.
})
// After that, b will be auto-reused on GC.
}
```