Commit 823d1e7087
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);
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();