| ... | @@ -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 likely | 9325 | <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 at | 9328 | 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#} or | 9329 | {#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> |
| 9876 | const std = @import("std"); | 9873 | const std = @import("std"); |
| 9877 | | 9874 | |
| 9878 | pub fn main() !void { | 9875 | pub 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); |
| 9881 | | 9879 | |
| 9882 | for (args) |arg, i| { | 9880 | for (args) |arg, i| { |
| 9883 | std.debug.warn("{}: {}\n", i, arg); | 9881 | std.debug.warn("{}: {}\n", i, arg); |