github.com/moontrade/wavm-go@v0.3.2-0.20220316110326-d229dd66ad65/memory.go (about) 1 package wavm 2 3 // #include <stdlib.h> 4 // #include "wavm-c.h" 5 import "C" 6 7 type Memory C.wasm_memory_t 8 9 //func NewMemory(compartment *C.wasm_compartment_t, memoryType *C.wasm_memorytype_t, debugName string) *C.wasm_memory_t { 10 // var name *C.char 11 // if debugName == "" { 12 // name = EMPTY 13 // } else { 14 // name = C.CString(debugName) 15 // defer C.free(unsafe.Pointer(name)) 16 // } 17 // return C.wasm_memory_new(compartment, memoryType, name) 18 //} 19 20 func (m *Memory) Close() error { 21 m.Delete() 22 return nil 23 } 24 25 func (m *Memory) Delete() { 26 C.wasm_memory_delete((*C.wasm_memory_t)(m)) 27 } 28 29 func (m *Memory) Data() *C.char { 30 return C.wasm_memory_data((*C.wasm_memory_t)(m)) 31 } 32 33 func (m *Memory) Size() int { 34 return int(C.wasm_memory_data_size((*C.wasm_memory_t)(m))) 35 } 36 37 func (m *Memory) Pages() int { 38 return int(C.wasm_memory_size((*C.wasm_memory_t)(m))) 39 } 40 41 func (m *Memory) Grow(delta int) (bool, int) { 42 var previousSize C.wasm_memory_pages_t 43 ok := bool(C.wasm_memory_grow((*C.wasm_memory_t)(m), (C.wasm_memory_pages_t)(delta), &previousSize)) 44 return ok, int(previousSize) 45 }