allegro / allegro/bigcache

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

Aperta
#229 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub
discussion enhancement help wanted
Lingua principale
Go
Stelle
8.2k
Fork
614
Merge medio
5g 12h
PR unite (30g)
1

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.