2024-09-30 10:46:23 +00:00
|
|
|
//go:build !(darwin || linux) || !(amd64 || arm64 || riscv64 || ppc64le) || sqlite3_noshm || sqlite3_nosys
|
2024-05-27 15:46:15 +00:00
|
|
|
|
2024-06-07 13:06:43 +00:00
|
|
|
package alloc
|
2024-05-27 15:46:15 +00:00
|
|
|
|
|
|
|
import "github.com/tetratelabs/wazero/experimental"
|
|
|
|
|
2024-06-07 13:06:43 +00:00
|
|
|
func Slice(cap, _ uint64) experimental.LinearMemory {
|
|
|
|
return &sliceMemory{make([]byte, 0, cap)}
|
2024-05-27 15:46:15 +00:00
|
|
|
}
|
|
|
|
|
2024-06-07 13:06:43 +00:00
|
|
|
type sliceMemory struct {
|
2024-05-27 15:46:15 +00:00
|
|
|
buf []byte
|
|
|
|
}
|
|
|
|
|
2024-06-07 13:06:43 +00:00
|
|
|
func (b *sliceMemory) Free() {}
|
2024-05-27 15:46:15 +00:00
|
|
|
|
2024-06-07 13:06:43 +00:00
|
|
|
func (b *sliceMemory) Reallocate(size uint64) []byte {
|
2024-05-27 15:46:15 +00:00
|
|
|
if cap := uint64(cap(b.buf)); size > cap {
|
|
|
|
b.buf = append(b.buf[:cap], make([]byte, size-cap)...)
|
|
|
|
} else {
|
|
|
|
b.buf = b.buf[:size]
|
|
|
|
}
|
|
|
|
return b.buf
|
|
|
|
}
|