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 9
9
"golang.org/x/sys/unix"
10
10
)
11
11
12
- func newAllocator (cap , max uint64 ) experimental.LinearMemory {
12
+ func virtualAlloc (cap , max uint64 ) experimental.LinearMemory {
13
13
// Round up to the page size.
14
14
rnd := uint64 (unix .Getpagesize () - 1 )
15
15
max = (max + rnd ) &^ rnd
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import (
11
11
"golang.org/x/sys/windows"
12
12
)
13
13
14
- func newAllocator (cap , max uint64 ) experimental.LinearMemory {
14
+ func virtualAlloc (cap , max uint64 ) experimental.LinearMemory {
15
15
// Round up to the page size.
16
16
rnd := uint64 (windows .Getpagesize () - 1 )
17
17
max = (max + rnd ) &^ rnd
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import (
14
14
15
15
func withAllocator (ctx context.Context ) context.Context {
16
16
return experimental .WithMemoryAllocator (ctx ,
17
- experimental .MemoryAllocatorFunc (newAllocator ))
17
+ experimental .MemoryAllocatorFunc (virtualAlloc ))
18
18
}
19
19
20
20
type 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
2
2
3
3
package util
4
4
5
- import "context"
5
+ import (
6
+ "context"
7
+
8
+ "github.com/tetratelabs/wazero/experimental"
9
+ )
6
10
7
11
type mmapState struct {}
8
12
9
13
func 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
+ }))
11
21
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 9
9
)
10
10
11
11
func init () {
12
- sqlite3 .RuntimeConfig = wazero .NewRuntimeConfig ().WithMemoryLimitPages (1024 )
12
+ sqlite3 .RuntimeConfig = wazero .NewRuntimeConfig ().
13
+ WithMemoryCapacityFromMax (true ).
14
+ WithMemoryLimitPages (1024 )
13
15
14
16
if os .Getenv ("CI" ) != "" {
15
17
path := filepath .Join (os .TempDir (), "wazero" )
You can’t perform that action at this time.
0 commit comments