mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 16:45:27 +00:00
add std.heap.wasm_allocator
This commit is contained in:
parent
4a701490d4
commit
823d1e7087
@ -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);
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user