zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 823d1e70876d79dfae9dde0496e7cf293995c44a (tree)
parent 4a701490d4c403938e093c6bfb32b8723eb01786
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon,  5 Dec 2022 17:20:06 -0700

add std.heap.wasm_allocator

Diffstat:
Mlib/std/heap.zig | 10++++++++++
Msrc/main.zig | 5+----
2 files changed, 11 insertions(+), 4 deletions(-)

diff --git 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 @@ -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();