Skip to content

Add MemorySize API to expose WASM linear memory size#1

Merged
wolfy-j merged 1 commit intomainfrom
feature/memory-size
Feb 17, 2026
Merged

Add MemorySize API to expose WASM linear memory size#1
wolfy-j merged 1 commit intomainfrom
feature/memory-size

Conversation

@wolfy-j
Copy link
Copy Markdown
Contributor

@wolfy-j wolfy-j commented Feb 17, 2026

This pull request introduces a new interface for querying the size of WASM linear memory and implements it throughout the engine and runtime layers. It also adds comprehensive tests to ensure correct behavior for memory sizing. The changes improve introspection capabilities for WASM instances and memory, making it easier to verify and debug memory allocation and usage.

New memory sizing interface and implementation:

  • Added the MemorySizer interface with a Size() method to wasm.go, and implemented it for WazeroMemory. This allows querying the current linear memory size in bytes. [1] [2]
  • Implemented the MemorySize() method for both WazeroInstance and high-level Instance, enabling users to easily retrieve memory size from WASM instances. [1] [2]

Testing enhancements:

  • Added unit tests for WazeroInstance.MemorySize() and WazeroMemory.Size() in engine/wazero_test.go, covering scenarios with different memory page sizes and nil memory.
  • Added a test for Instance.MemorySize() in runtime/runtime_test.go, validating memory size for a loaded WASM component and ensuring it is a non-zero multiple of the page size.

Add MemorySizer interface to wasmruntime, Size() to WazeroMemory,
MemorySize() to WazeroInstance and runtime.Instance. Returns current
linear memory size in bytes, or 0 when no memory is present.
@wolfy-j wolfy-j merged commit b2fd993 into main Feb 17, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant