book will grow and malloc buffer to hold data. bookSize: The size of data that can be read at once. maxSize: The maximum size of data between two Release(). In some cases, this can guarantee all data allocated in one node to reduce copy.
(bookSize, maxSize int)
| 700 | // |
| 701 | // guarantee all data allocated in one node to reduce copy. |
| 702 | func (b *UnsafeLinkBuffer) book(bookSize, maxSize int) (p []byte) { |
| 703 | l := cap(b.write.buf) - b.write.malloc |
| 704 | // grow linkBuffer |
| 705 | if l == 0 { |
| 706 | l = maxSize |
| 707 | b.write.next = newLinkBufferNode(maxSize) |
| 708 | b.write = b.write.next |
| 709 | } |
| 710 | if l > bookSize { |
| 711 | l = bookSize |
| 712 | } |
| 713 | return b.write.Malloc(l) |
| 714 | } |
| 715 | |
| 716 | // bookAck will ack the first n malloc bytes and discard the rest. |
| 717 | // |