wasmedge-hs-0.17.1.0: Haskell bindings for the WasmEdge WebAssembly runtime
Copyright(c) 2026 Tushar Adhatrao
LicenseMIT
Stabilitystable
Safe HaskellNone
LanguageGHC2021

WasmEdge.Memory

Description

Provides types and functions for inspecting and manipulating WebAssembly linear memory instances:

  • MemoryType — describes the page limits of a linear memory
  • MemoryInstance — a runtime linear memory instance with byte-level read/write
Synopsis

Memory type

data MemoryType #

A WebAssembly linear memory type, specifying min/max page limits.

createMemoryType :: Limit -> IO MemoryType #

Create a MemoryType with the given Limit. 1 page = 64 KiB (65,536 bytes).

withMemoryType :: Limit -> (MemoryType -> IO a) -> IO a #

Scoped MemoryType.

Memory instance

data MemoryInstance #

A runtime WebAssembly linear memory instance.

getMemoryData :: MemoryInstance -> Word32 -> Word32 -> IO (WasmResult ByteString) #

Read length bytes from linear memory starting at offset.

setMemoryData :: MemoryInstance -> Word32 -> ByteString -> IO (WasmResult ()) #

Write a ByteString into linear memory starting at offset.

getMemoryPointer :: MemoryInstance -> Word32 -> Word32 -> IO (Ptr Word8) #

Get a direct pointer to linear memory at offset for length bytes. The pointer is valid only as long as the memory is not grown and the instance is alive.

getMemoryPageSize :: MemoryInstance -> IO Word32 #

Get the current size in pages (1 page = 64 KiB).

growMemoryPages :: MemoryInstance -> Word32 -> IO (WasmResult ()) #

Grow linear memory by pageCount pages.

Internal / borrowed pointers

borrowMemory :: Ptr MemoryInstanceTag -> IO MemoryInstance #

Create a borrowed MemoryInstance from a raw pointer (does not finalize).

unsafeMemoryTypePtr :: MemoryType -> IO (Ptr MemoryTypeTag) #

Extract the raw pointer of a MemoryType.

borrowMemoryType :: Ptr MemoryTypeTag -> IO MemoryType #

Create a borrowed MemoryType from a raw pointer (does not finalize).

disarmMemory :: MemoryInstance -> IO () #

Disarm finalizer when ownership is transferred to a module instance.