add std.heap.wasm_allocator

This commit is contained in:
Andrew Kelley 2022-12-05 17:20:06 -07:00
parent 4a701490d4
commit 823d1e7087
2 changed files with 11 additions and 4 deletions

View File

@ -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);

View File

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