Skip to content

Commit 67a538e

Browse files
authored
s2: add GetBufferCapacity() method (#832)
Add GetBufferCapacity() method. We are reusing readers with sync.Pool and we'd like to avoid allocating memory for the default block size since most of the inputs are smaller. To have a better estimate of how big the lazy buffer should be, we are thinking about keeping in mind a running average of the internal buffer capacities. This method would allow us to implement that.
1 parent eff45bd commit 67a538e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

s2/reader.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ type Reader struct {
147147
ignoreCRC bool
148148
}
149149

150+
// GetBufferCapacity returns the capacity of the internal buffer.
151+
// This might be useful to know when reusing the same reader in combination
152+
// with the lazy buffer option.
153+
func (r *Reader) GetBufferCapacity() int {
154+
return cap(r.buf)
155+
}
156+
150157
// ensureBufferSize will ensure that the buffer can take at least n bytes.
151158
// If false is returned the buffer exceeds maximum allowed size.
152159
func (r *Reader) ensureBufferSize(n int) bool {

0 commit comments

Comments
 (0)