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...@@ -224,6 +224,16 @@ else
224 .vtable = &PageAllocator.vtable,224 .vtable = &PageAllocator.vtable,
225 };225 };
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
227/// Verifies that the adjusted length will still map to the full length237/// Verifies that the adjusted length will still map to the full length
228pub fn alignPageAllocLen(full_len: usize, len: usize) usize {238pub fn alignPageAllocLen(full_len: usize, len: usize) usize {
229 const aligned_len = mem.alignAllocLen(full_len, len);239 const aligned_len = mem.alignAllocLen(full_len, len);
src/main.zig+1-4
...@@ -155,10 +155,7 @@ pub fn main() anyerror!void {...@@ -155,10 +155,7 @@ pub fn main() anyerror!void {
155 const use_gpa = (build_options.force_gpa or !builtin.link_libc) and builtin.os.tag != .wasi;155 const use_gpa = (build_options.force_gpa or !builtin.link_libc) and builtin.os.tag != .wasi;
156 const gpa = gpa: {156 const gpa = gpa: {
157 if (builtin.os.tag == .wasi) {157 if (builtin.os.tag == .wasi) {
158 break :gpa Allocator{158 break :gpa std.heap.wasm_allocator;
159 .ptr = undefined,
160 .vtable = &std.heap.WasmAllocator.vtable,
161 };
162 }159 }
163 if (use_gpa) {160 if (use_gpa) {
164 break :gpa general_purpose_allocator.allocator();161 break :gpa general_purpose_allocator.allocator();