github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/perf/bbp/example_test.go (about) 1 package bbp 2 3 import "fmt" 4 5 func ExampleGet() { 6 buf := Get(0, 50) 7 defer Put(buf) 8 9 buf = append(buf, "first line\n"...) 10 buf = append(buf, "second line\n"...) 11 12 fmt.Println(string(buf)) 13 14 // Output: 15 // first line 16 // second line 17 } 18 19 func ExampleGrow() { 20 buf := []byte("first line\n") 21 buf = Grow(buf, 50, true) 22 buf = append(buf, "second line\n"...) 23 24 fmt.Println(string(buf)) 25 Put(buf) 26 27 // Output: 28 // first line 29 // second line 30 } 31 32 func ExamplePool() { 33 var pool Pool 34 buf := pool.GetBuffer() 35 defer PutBuffer(buf) 36 37 buf.WriteString("first line\n") 38 buf.Write([]byte("second line\n")) 39 40 fmt.Println(buf.String()) 41 42 // Output: 43 // first line 44 // second line 45 } 46 47 func ExampleBuffer() { 48 var buf Buffer 49 defer PutBuffer(&buf) 50 51 buf.WriteString("first line\n") 52 buf.Write([]byte("second line\n")) 53 buf.buf = append(buf.buf, "third line\n"...) 54 55 fmt.Println(buf.String()) 56 57 // Output: 58 // first line 59 // second line 60 // third line 61 }