mirror of
https://github.com/lkmio/lkm.git
synced 2025-10-04 06:46:24 +08:00
33 lines
516 B
Go
33 lines
516 B
Go
package stream
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"github.com/yangjiechina/avformat/utils"
|
|
"testing"
|
|
"unsafe"
|
|
)
|
|
|
|
func TestMemoryPool(t *testing.T) {
|
|
bytes := make([]byte, 10)
|
|
for i := 0; i < 10; i++ {
|
|
bytes[i] = byte(i)
|
|
}
|
|
|
|
pool := NewMemoryPool(5)
|
|
last := uintptr(0)
|
|
for i := 0; i < 10; i++ {
|
|
pool.Mark()
|
|
pool.Write(bytes)
|
|
fetch := pool.Fetch()
|
|
addr := *(*uintptr)(unsafe.Pointer(&fetch))
|
|
if last != 0 {
|
|
utils.Assert(last == addr)
|
|
}
|
|
last = addr
|
|
|
|
println(hex.Dump(fetch))
|
|
|
|
pool.FreeTail()
|
|
}
|
|
}
|