@@ -6,21 +6,36 @@ import (
6
6
"github.com/tetratelabs/wazero/internal/expctxkeys"
7
7
)
8
8
9
- // MemoryAllocator is a memory allocation hook which is invoked
10
- // to create a new MemoryBuffer, with the given specification:
11
- // min is the initial and minimum length (in bytes) of the backing []byte,
12
- // cap a suggested initial capacity, and max the maximum length
13
- // that will ever be requested.
14
- type MemoryAllocator func (min , cap , max uint64 ) MemoryBuffer
9
+ // MemoryAllocator is a memory allocation hook,
10
+ // invoked to create a LinearMemory.
11
+ type MemoryAllocator interface {
12
+ // Allocate should create a new LinearMemory with the given specification:
13
+ // cap is the suggested initial capacity for the backing []byte,
14
+ // and max the maximum length that will ever be requested.
15
+ //
16
+ // Notes:
17
+ // - To back a shared memory, the address of the backing []byte cannot
18
+ // change. This is checked at runtime. Implementations should document
19
+ // if the returned LinearMemory meets this requirement.
20
+ Allocate (cap , max uint64 ) LinearMemory
21
+ }
22
+
23
+ // MemoryAllocatorFunc is a convenience for defining inlining a MemoryAllocator.
24
+ type MemoryAllocatorFunc func (cap , max uint64 ) LinearMemory
25
+
26
+ // Allocate implements MemoryAllocator.Allocate.
27
+ func (f MemoryAllocatorFunc ) Allocate (cap , max uint64 ) LinearMemory {
28
+ return f (cap , max )
29
+ }
15
30
16
- // MemoryBuffer is a memory buffer that backs a Wasm memory.
17
- type MemoryBuffer interface {
18
- // Buffer returns the backing []byte for the memory buffer .
19
- Buffer () [] byte
20
- // Grow the backing memory buffer to size bytes in length.
21
- // To back a shared memory, Grow can't change the address
22
- // of the backing []byte (only its length/capacity may change).
23
- Grow (size uint64 ) []byte
31
+ // LinearMemory is an expandable []byte that backs a Wasm linear memory.
32
+ type LinearMemory interface {
33
+ // Reallocates the linear memory to size bytes in length .
34
+ //
35
+ // Notes:
36
+ // - To back a shared memory, Reallocate can't change the address of the
37
+ // backing []byte (only its length/capacity may change).
38
+ Reallocate (size uint64 ) []byte
24
39
// Free the backing memory buffer.
25
40
Free ()
26
41
}
0 commit comments