Class MemoryAllocators

java.lang.Object
ai.tegmentum.webassembly4j.runtime.marshal.MemoryAllocators

public final class MemoryAllocators extends Object
Factory for creating MemoryAllocator instances.

Provides automatic discovery from a WASM instance as well as explicit constructors.

  • Method Details

    • fromInstance

      public static MemoryAllocator fromInstance(ai.tegmentum.webassembly4j.api.Instance instance)
      Creates an allocator from a WASM instance by probing for known allocation exports.

      Discovery order:

      1. cabi_realloc — Component Model Canonical ABI
      2. 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

      public static MemoryAllocator cabiRealloc(ai.tegmentum.webassembly4j.api.Function cabiRealloc)
      Creates an allocator backed by the cabi_realloc function.
      Parameters:
      cabiRealloc - the cabi_realloc function
      Returns:
      a CabiRealloc-based allocator
    • bump

      public static BumpAllocator bump(int startOffset, int limit)
      Creates a bump allocator for linear memory.
      Parameters:
      startOffset - the starting offset for allocations
      limit - the maximum offset (exclusive)
      Returns:
      a bump allocator