Get gets a []byte of len size with cap <= size*2.
(size int)
| 27 | |
| 28 | // Get gets a []byte of len size with cap <= size*2. |
| 29 | func Get(size int) *[]byte { |
| 30 | i := getPoolIdx(size) |
| 31 | if i >= len(pools) { |
| 32 | buf := make([]byte, size) |
| 33 | return &buf |
| 34 | } |
| 35 | |
| 36 | ptrBuf := (pools[i].Get().(*[]byte)) |
| 37 | *ptrBuf = (*ptrBuf)[:size] |
| 38 | |
| 39 | return ptrBuf |
| 40 | } |
| 41 | |
| 42 | func getPoolIdx(size int) int { |
| 43 | if size < 2 { |