diff --git a/lib/std/heap.zig b/lib/std/heap.zig index ac77db7a79..ee6525659e 100644 --- a/lib/std/heap.zig +++ b/lib/std/heap.zig @@ -224,6 +224,16 @@ else .vtable = &PageAllocator.vtable, }; +/// This allocator is fast, small, and specific to WebAssembly. In the future, +/// this will be the implementation automatically selected by +/// `GeneralPurposeAllocator` when compiling in `ReleaseSmall` mode for wasm32 +/// and wasm64 architectures. +/// Until then, it is available here to play with. +pub const wasm_allocator = Allocator{ + .ptr = undefined, + .vtable = &std.heap.WasmAllocator.vtable, +}; + /// Verifies that the adjusted length will still map to the full length pub fn alignPageAllocLen(full_len: usize, len: usize) usize { const aligned_len = mem.alignAllocLen(full_len, len); diff --git a/src/main.zig b/src/main.zig index 1db5693e36..67b67fa923 100644 --- a/src/main.zig +++ b/src/main.zig @@ -155,10 +155,7 @@ pub fn main() anyerror!void { const use_gpa = (build_options.force_gpa or !builtin.link_libc) and builtin.os.tag != .wasi; const gpa = gpa: { if (builtin.os.tag == .wasi) { - break :gpa Allocator{ - .ptr = undefined, - .vtable = &std.heap.WasmAllocator.vtable, - }; + break :gpa std.heap.wasm_allocator; } if (use_gpa) { break :gpa general_purpose_allocator.allocator();