Giving control of memory allocation/resize to user code
Author: martinfouilleulCreated Sep 13, 2022Updated Aug 26, 2026
LabelsAPI
Would it be possible to pass a MemoryResize callback to M3Runtime, so that the memory allocation strategy can be controlled from user side?
E.g. my current use case is reserving 4gb of virtual memory upfront with mmap, and committing new pages only when memory needs to grow.
This both avoids an unnecessary copy and guarantees that memory addresses are stable, so I can actually provide a native memory allocator on the embedder side and expose it to wasm code (instead of compiling the allocator to wasm).
For now I just hacked in my own callback and user pointer in M3Runtime, but it would be nice to have an 'official' API. I can clean it up and submit a PR if you think this is useful.
Source: wasm3/wasm3