mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 15:00:26 +08:00
提升内存缓存的碎片内存复用效率
This commit is contained in:
@@ -33,7 +33,16 @@ func NewMemoryWriter(memoryStorage *MemoryStorage, key string, expiredAt int64,
|
||||
Status: status,
|
||||
}
|
||||
if expectedBodySize > 0 {
|
||||
valueItem.BodyValue = make([]byte, expectedBodySize)
|
||||
bodyBytes, ok := SharedFragmentMemoryPool.Get(expectedBodySize) // try to reuse memory
|
||||
if ok {
|
||||
valueItem.BodyValue = bodyBytes
|
||||
} else {
|
||||
if expectedBodySize >= minMemoryFragmentPoolItemSize {
|
||||
SharedFragmentMemoryPool.IncreaseNew()
|
||||
}
|
||||
valueItem.BodyValue = make([]byte, expectedBodySize)
|
||||
}
|
||||
|
||||
valueItem.IsPrepared = true
|
||||
}
|
||||
var w = &MemoryWriter{
|
||||
|
||||
Reference in New Issue
Block a user