MCPcopy
hub / github.com/grpc/grpc-go / NewBuffer

Function NewBuffer

mem/buffers.go:107–122  ·  view source on GitHub ↗

NewBuffer creates a new Buffer from the given data, initializing the reference counter to 1. The data will then be returned to the given pool when all references to the returned Buffer are released. As a special case to avoid additional allocations, if the given buffer pool is nil, the returned buff

(data *[]byte, pool BufferPool)

Source from the content-addressed store, hash-verified

105//
106// Note that the backing array of the given data is not copied.
107func NewBuffer(data *[]byte, pool BufferPool) Buffer {
108 // Use the buffer's capacity instead of the length, otherwise buffers may
109 // not be reused under certain conditions. For example, if a large buffer
110 // is acquired from the pool, but fewer bytes than the buffering threshold
111 // are written to it, the buffer will not be returned to the pool.
112 if pool == nil || IsBelowBufferPoolingThreshold(cap(*data)) {
113 return (SliceBuffer)(*data)
114 }
115 b := newBuffer()
116 b.origData = data
117 b.data = *data
118 b.pool = pool
119 b.rootBuf = b
120 b.refs.Store(1)
121 return b
122}
123
124// Copy creates a new Buffer from the given data, initializing the reference
125// counter to 1.

Callers 12

mustCompressFunction · 0.92
MarshalMethod · 0.92
readDataFrameMethod · 0.92
HandleStreamsMethod · 0.92
TestBuffer_SplitMethod · 0.92
TestBuffer_SliceMethod · 0.92
newBufferFunction · 0.92
MaterializeToBufferMethod · 0.85
ReadAllFunction · 0.85
CopyFunction · 0.85

Calls 2

newBufferFunction · 0.70

Tested by 6

mustCompressFunction · 0.74
TestBuffer_SplitMethod · 0.74
TestBuffer_SliceMethod · 0.74
newBufferFunction · 0.74