authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-25 19:30:41-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-25 19:30:41-05:00
logf8a2dec243d9bbfed8cd21528ccd93c4f4b9163e
treedf56bb2bc488e66c75a31068febac4eb8fd4b454
parent6b7e1085e38878419547ea74f0ce7259636b80b8
signaturelock-open Commit is signed but in an unrecognized format.

docs: update references to wasm_allocator


2 files changed, 5 insertions(+), 7 deletions(-)

doc/langref.html.in+4-6
...@@ -9324,8 +9324,6 @@ fn concat(allocator: *Allocator, a: []const u8, b: []const u8) ![]u8 {...@@ -9324,8 +9324,6 @@ fn concat(allocator: *Allocator, a: []const u8, b: []const u8) ![]u8 {
9324 </li>9324 </li>
9325 <li>Are you linking libc? In this case, {#syntax#}std.heap.c_allocator{#endsyntax#} is likely9325 <li>Are you linking libc? In this case, {#syntax#}std.heap.c_allocator{#endsyntax#} is likely
9326 the right choice, at least for your main allocator.</li>9326 the right choice, at least for your main allocator.</li>
9327 <li>Are you building for WebAssembly? In this case, {#syntax#}std.heap.wasm_allocator{#endsyntax#} is likely
9328 the right choice for your main allocator as it uses WebAssembly's memory instructions.</li>
9329 <li>9327 <li>
9330 Is the maximum number of bytes that you will need bounded by a number known at9328 Is the maximum number of bytes that you will need bounded by a number known at
9331 {#link|comptime#}? In this case, use {#syntax#}std.heap.FixedBufferAllocator{#endsyntax#} or9329 {#link|comptime#}? In this case, use {#syntax#}std.heap.FixedBufferAllocator{#endsyntax#} or
...@@ -9841,8 +9839,7 @@ all your base are belong to us</code></pre>...@@ -9841,8 +9839,7 @@ all your base are belong to us</code></pre>
9841 {#header_close#}9839 {#header_close#}
9842 {#header_close#}9840 {#header_close#}
9843 {#header_open|WebAssembly#}9841 {#header_open|WebAssembly#}
9844 <p>Zig supports building for WebAssembly out of the box. There is also a specialized {#syntax#}std.heap.wasm_allocator{#endsyntax#}9842 <p>Zig supports building for WebAssembly out of the box.</p>
9845 memory allocator for WebAssembly environments.</p>
9846 {#header_open|Freestanding#}9843 {#header_open|Freestanding#}
9847 <p>For host environments like the web browser and nodejs, build as a library using the freestanding OS target.9844 <p>For host environments like the web browser and nodejs, build as a library using the freestanding OS target.
9848 Here's an example of running Zig code compiled to WebAssembly with nodejs.</p>9845 Here's an example of running Zig code compiled to WebAssembly with nodejs.</p>
...@@ -9876,8 +9873,9 @@ The result is 3</code></pre>...@@ -9876,8 +9873,9 @@ The result is 3</code></pre>
9876const std = @import("std");9873const std = @import("std");
98779874
9878pub fn main() !void {9875pub fn main() !void {
9879 const args = try std.process.argsAlloc(std.heap.wasm_allocator);9876 // TODO a better default allocator that isn't as wasteful!
9880 defer std.process.argsFree(std.heap.wasm_allocator, args);9877 const args = try std.process.argsAlloc(std.heap.page_allocator);
9878 defer std.process.argsFree(std.heap.page_allocator, args);
98819879
9882 for (args) |arg, i| {9880 for (args) |arg, i| {
9883 std.debug.warn("{}: {}\n", i, arg);9881 std.debug.warn("{}: {}\n", i, arg);
lib/std/process.zig+1-1
...@@ -79,7 +79,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {...@@ -79,7 +79,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
79 // https://github.com/WebAssembly/WASI/issues/2779 // https://github.com/WebAssembly/WASI/issues/27
80 var environ = try allocator.alloc(?[*:0]u8, environ_count + 1);80 var environ = try allocator.alloc(?[*:0]u8, environ_count + 1);
81 defer allocator.free(environ);81 defer allocator.free(environ);
82 var environ_buf = try std.heap.wasm_allocator.alloc(u8, environ_buf_size);82 var environ_buf = try std.heap.page_allocator.alloc(u8, environ_buf_size);
83 defer allocator.free(environ_buf);83 defer allocator.free(environ_buf);
8484
85 const environ_get_ret = os.wasi.environ_get(environ.ptr, environ_buf.ptr);85 const environ_get_ret = os.wasi.environ_get(environ.ptr, environ_buf.ptr);