Class MemoryAllocators
java.lang.Object
ai.tegmentum.webassembly4j.runtime.marshal.MemoryAllocators
Factory for creating
MemoryAllocator instances.
Provides automatic discovery from a WASM instance as well as explicit constructors.
-
Method Summary
Modifier and TypeMethodDescriptionstatic BumpAllocatorbump(int startOffset, int limit) Creates a bump allocator for linear memory.static MemoryAllocatorcabiRealloc(ai.tegmentum.webassembly4j.api.Function cabiRealloc) Creates an allocator backed by thecabi_reallocfunction.static MemoryAllocatorfromInstance(ai.tegmentum.webassembly4j.api.Instance instance) Creates an allocator from a WASM instance by probing for known allocation exports.
-
Method Details
-
fromInstance
Creates an allocator from a WASM instance by probing for known allocation exports.Discovery order:
cabi_realloc— Component Model Canonical ABI- Bump allocator using the exported
memory
- Parameters:
instance- the WASM instance- Returns:
- an allocator for the instance
- Throws:
IllegalStateException- if no allocator can be created
-
cabiRealloc
Creates an allocator backed by thecabi_reallocfunction.- Parameters:
cabiRealloc- the cabi_realloc function- Returns:
- a CabiRealloc-based allocator
-
bump
Creates a bump allocator for linear memory.- Parameters:
startOffset- the starting offset for allocationslimit- the maximum offset (exclusive)- Returns:
- a bump allocator
-