authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-05 17:20:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-06 12:27:28-07:00
log823d1e70876d79dfae9dde0496e7cf293995c44a
treee39e625d4e934b87d8b48770eff9dd5d720d0617
parent4a701490d4c403938e093c6bfb32b8723eb01786

add std.heap.wasm_allocator


2 files changed, 11 insertions(+), 4 deletions(-)

lib/std/heap.zig+10
......@@ -224,6 +224,16 @@ else
224224 .vtable = &PageAllocator.vtable,
225225 };
226226
227/// This allocator is fast, small, and specific to WebAssembly. In the future,
228/// this will be the implementation automatically selected by
229/// `GeneralPurposeAllocator` when compiling in `ReleaseSmall` mode for wasm32
230/// and wasm64 architectures.
231/// Until then, it is available here to play with.
232pub const wasm_allocator = Allocator{
233 .ptr = undefined,
234 .vtable = &std.heap.WasmAllocator.vtable,
235};
236
227237/// Verifies that the adjusted length will still map to the full length
228238pub fn alignPageAllocLen(full_len: usize, len: usize) usize {
229239 const aligned_len = mem.alignAllocLen(full_len, len);
src/main.zig+1-4
......@@ -155,10 +155,7 @@ pub fn main() anyerror!void {
155155 const use_gpa = (build_options.force_gpa or !builtin.link_libc) and builtin.os.tag != .wasi;
156156 const gpa = gpa: {
157157 if (builtin.os.tag == .wasi) {
158 break :gpa Allocator{
159 .ptr = undefined,
160 .vtable = &std.heap.WasmAllocator.vtable,
161 };
158 break :gpa std.heap.wasm_allocator;
162159 }
163160 if (use_gpa) {
164161 break :gpa general_purpose_allocator.allocator();