测试合并写

This commit is contained in:
yangjiechina
2023-12-03 23:35:55 +08:00
parent 0149865a26
commit baebd7d25d
5 changed files with 122 additions and 15 deletions

View File

@@ -25,6 +25,8 @@ type MemoryPool interface {
// FreeTail 从尾部释放指定大小内存
FreeTail()
Data() ([]byte, []byte)
}
func NewMemoryPool(capacity int) MemoryPool {
@@ -135,3 +137,12 @@ func (m *memoryPool) FreeTail() {
m.tail = m.capacity
}
}
func (m *memoryPool) Data() ([]byte, []byte) {
if m.tail <= m.head {
return m.data[m.head:], m.data[:m.tail]
} else {
return m.data[m.head:m.tail], nil
}
}