allegro / allegro/bigcache

FeatureRequest: provide a way to reuse byte slice allocated in readEntry

Đang mở
#229 7 bình luận 0 reaction 0 người được giao Xem trên GitHub
discussion enhancement help wanted
Ngôn ngữ chính
Go
Star
8.2k
Fork
614
Merge trung bình
5 ngày 12 giờ
Pull request đã merge (30 ngày)
1

Mô tả

Currently we allocate a byte slice directly in encoding.go:readEntry. Can we provide a way to reuse slice here?

Here are my two possible solutions.
First one is provide a new function like
```
func (c *BigCache) GetWithReuseFunc(key string) (value []byte,reuseFunc func(*[]byte),err error)
```
once users don't need value anymore, they can use reuseFunc(&value) to give the slice back to BigCache, internally we can maintain some sync.Pools to reuse different sized slices.

Second one is
```
func (c *BigCache) GetWithPreallocatedSlice(key string, preallocated []byte) (value []byte, err error)
```
users can provide a preallocated slice to that function, just like io.Reader or https://github.com/golang/snappy/blob/master/decode.go#L57. If that slice is large enough, we can use and return it directly, otherwise, we return a newly allocated slice.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.