mirror of
https://github.com/lkmio/lkm.git
synced 2025-10-05 15:16:49 +08:00
26 lines
363 B
Go
26 lines
363 B
Go
package stream
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"testing"
|
|
)
|
|
|
|
func TestMemoryPool(t *testing.T) {
|
|
bytes := make([]byte, 10)
|
|
for i := 0; i < 10; i++ {
|
|
bytes[i] = byte(i)
|
|
}
|
|
|
|
pool := NewMemoryPool(5)
|
|
for i := 0; i < 10; i++ {
|
|
pool.Mark()
|
|
pool.Write(bytes)
|
|
fetch := pool.Fetch()
|
|
println(hex.Dump(fetch))
|
|
|
|
if i%2 == 0 {
|
|
pool.FreeHead(len(fetch))
|
|
}
|
|
}
|
|
}
|