File tree Expand file tree Collapse file tree 8 files changed +53
-23
lines changed Expand file tree Collapse file tree 8 files changed +53
-23
lines changed Original file line number Diff line number Diff line change 1+ //go:build !(unix || windows) || sqlite3_nosys
2+
3+ package util
4+
5+ import "github.com/tetratelabs/wazero/experimental"
6+
7+ func virtualAlloc (cap , max uint64 ) experimental.LinearMemory {
8+ return sliceAlloc (cap , max )
9+ }
Original file line number Diff line number Diff line change 1+ //go:build !(darwin || linux) || !(amd64 || arm64 || riscv64) || sqlite3_noshm || sqlite3_nosys
2+
3+ package util
4+
5+ import "github.com/tetratelabs/wazero/experimental"
6+
7+ func sliceAlloc (cap , max uint64 ) experimental.LinearMemory {
8+ return & sliceBuffer {make ([]byte , cap ), max }
9+ }
10+
11+ type sliceBuffer struct {
12+ buf []byte
13+ max uint64
14+ }
15+
16+ func (b * sliceBuffer ) Free () {}
17+
18+ func (b * sliceBuffer ) Reallocate (size uint64 ) []byte {
19+ if cap := uint64 (cap (b .buf )); size > cap {
20+ b .buf = append (b .buf [:cap ], make ([]byte , size - cap )... )
21+ } else {
22+ b .buf = b .buf [:size ]
23+ }
24+ return b .buf
25+ }
Original file line number Diff line number Diff line change 99 "golang.org/x/sys/unix"
1010)
1111
12- func newAllocator (cap , max uint64 ) experimental.LinearMemory {
12+ func virtualAlloc (cap , max uint64 ) experimental.LinearMemory {
1313 // Round up to the page size.
1414 rnd := uint64 (unix .Getpagesize () - 1 )
1515 max = (max + rnd ) &^ rnd
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import (
1111 "golang.org/x/sys/windows"
1212)
1313
14- func newAllocator (cap , max uint64 ) experimental.LinearMemory {
14+ func virtualAlloc (cap , max uint64 ) experimental.LinearMemory {
1515 // Round up to the page size.
1616 rnd := uint64 (windows .Getpagesize () - 1 )
1717 max = (max + rnd ) &^ rnd
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import (
1414
1515func withAllocator (ctx context.Context ) context.Context {
1616 return experimental .WithMemoryAllocator (ctx ,
17- experimental .MemoryAllocatorFunc (newAllocator ))
17+ experimental .MemoryAllocatorFunc (virtualAlloc ))
1818}
1919
2020type mmapState struct {
Original file line number Diff line number Diff line change 1- //go:build !(darwin || linux || windows ) || !(amd64 || arm64 || riscv64) || sqlite3_noshm || sqlite3_nosys
1+ //go:build !(darwin || linux) || !(amd64 || arm64 || riscv64) || sqlite3_noshm || sqlite3_nosys
22
33package util
44
5- import "context"
5+ import (
6+ "context"
7+
8+ "github.com/tetratelabs/wazero/experimental"
9+ )
610
711type mmapState struct {}
812
913func withAllocator (ctx context.Context ) context.Context {
10- return ctx
14+ return experimental .WithMemoryAllocator (ctx ,
15+ experimental .MemoryAllocatorFunc (func (cap , max uint64 ) experimental.LinearMemory {
16+ if cap == max {
17+ return virtualAlloc (cap , max )
18+ }
19+ return sliceAlloc (cap , max )
20+ }))
1121}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 99)
1010
1111func init () {
12- sqlite3 .RuntimeConfig = wazero .NewRuntimeConfig ().WithMemoryLimitPages (1024 )
12+ sqlite3 .RuntimeConfig = wazero .NewRuntimeConfig ().
13+ WithMemoryCapacityFromMax (true ).
14+ WithMemoryLimitPages (1024 )
1315
1416 if os .Getenv ("CI" ) != "" {
1517 path := filepath .Join (os .TempDir (), "wazero" )
You can’t perform that action at this time.
0 commit comments