diff options
| author | Lee Cannon <leecannon@leecannon.xyz> | 2021-10-29 02:03:15 +0100 |
|---|---|---|
| committer | Lee Cannon <leecannon@leecannon.xyz> | 2021-11-30 23:32:47 +0000 |
| commit | 75548b50ff23a3de48d166170425001c073d27c1 (patch) | |
| tree | de47b7ae071228835ce9108f12f0ed9612f729c7 /doc | |
| parent | 47bc13bc597622fc8deffa1c1a45d47dac51eeb0 (diff) | |
| download | zig-75548b50ff23a3de48d166170425001c073d27c1.tar.gz zig-75548b50ff23a3de48d166170425001c073d27c1.zip | |
allocgate: stage 1 and 2 building
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/docgen.zig | 2 | ||||
| -rw-r--r-- | doc/langref.html.in | 26 |
2 files changed, 14 insertions, 14 deletions
diff --git a/doc/docgen.zig b/doc/docgen.zig index ed469caf9e..1f6ff74617 100644 --- a/doc/docgen.zig +++ b/doc/docgen.zig @@ -21,7 +21,7 @@ pub fn main() !void { var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); defer arena.deinit(); - const allocator = &arena.allocator; + const allocator = arena.getAllocator(); var args_it = process.args(); diff --git a/doc/langref.html.in b/doc/langref.html.in index 89a9b16a2e..631c948628 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -7362,7 +7362,7 @@ fn amain() !void { } var global_download_frame: anyframe = undefined; -fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { +fn fetchUrl(allocator: Allocator, url: []const u8) ![]u8 { _ = url; // this is just an example, we don't actually do it! const result = try allocator.dupe(u8, "this is the downloaded url contents"); errdefer allocator.free(result); @@ -7374,7 +7374,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { } var global_file_frame: anyframe = undefined; -fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { +fn readFile(allocator: Allocator, filename: []const u8) ![]u8 { _ = filename; // this is just an example, we don't actually do it! const result = try allocator.dupe(u8, "this is the file contents"); errdefer allocator.free(result); @@ -7433,7 +7433,7 @@ fn amain() !void { std.debug.print("file_text: {s}\n", .{file_text}); } -fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { +fn fetchUrl(allocator: Allocator, url: []const u8) ![]u8 { _ = url; // this is just an example, we don't actually do it! const result = try allocator.dupe(u8, "this is the downloaded url contents"); errdefer allocator.free(result); @@ -7441,7 +7441,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { return result; } -fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { +fn readFile(allocator: Allocator, filename: []const u8) ![]u8 { _ = filename; // this is just an example, we don't actually do it! const result = try allocator.dupe(u8, "this is the file contents"); errdefer allocator.free(result); @@ -10050,8 +10050,8 @@ pub fn main() void { C has a default allocator - <code>malloc</code>, <code>realloc</code>, and <code>free</code>. When linking against libc, Zig exposes this allocator with {#syntax#}std.heap.c_allocator{#endsyntax#}. However, by convention, there is no default allocator in Zig. Instead, functions which need to - allocate accept an {#syntax#}*Allocator{#endsyntax#} parameter. Likewise, data structures such as - {#syntax#}std.ArrayList{#endsyntax#} accept an {#syntax#}*Allocator{#endsyntax#} parameter in + allocate accept an {#syntax#}Allocator{#endsyntax#} parameter. Likewise, data structures such as + {#syntax#}std.ArrayList{#endsyntax#} accept an {#syntax#}Allocator{#endsyntax#} parameter in their initialization functions: </p> {#code_begin|test|allocator#} @@ -10061,12 +10061,12 @@ const expect = std.testing.expect; test "using an allocator" { var buffer: [100]u8 = undefined; - const allocator = &std.heap.FixedBufferAllocator.init(&buffer).allocator; + const allocator = std.heap.FixedBufferAllocator.init(&buffer).getAllocator(); const result = try concat(allocator, "foo", "bar"); try expect(std.mem.eql(u8, "foobar", result)); } -fn concat(allocator: *Allocator, a: []const u8, b: []const u8) ![]u8 { +fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 { const result = try allocator.alloc(u8, a.len + b.len); std.mem.copy(u8, result, a); std.mem.copy(u8, result[a.len..], b); @@ -10091,7 +10091,7 @@ fn concat(allocator: *Allocator, a: []const u8, b: []const u8) ![]u8 { </p> <ol> <li> - Are you making a library? In this case, best to accept an {#syntax#}*Allocator{#endsyntax#} + Are you making a library? In this case, best to accept an {#syntax#}Allocator{#endsyntax#} as a parameter and allow your library's users to decide what allocator to use. </li> <li>Are you linking libc? In this case, {#syntax#}std.heap.c_allocator{#endsyntax#} is likely @@ -10114,7 +10114,7 @@ pub fn main() !void { var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); defer arena.deinit(); - const allocator = &arena.allocator; + const allocator = arena.getAllocator(); const ptr = try allocator.create(i32); std.debug.print("ptr={*}\n", .{ptr}); @@ -10281,7 +10281,7 @@ test "string literal to constant slice" { <p> For example, the function's documentation may say "caller owns the returned memory", in which case the code that calls the function must have a plan for when to free that memory. Probably in this situation, - the function will accept an {#syntax#}*Allocator{#endsyntax#} parameter. + the function will accept an {#syntax#}Allocator{#endsyntax#} parameter. </p> <p> Sometimes the lifetime of a pointer may be more complicated. For example, the @@ -10820,7 +10820,7 @@ const std = @import("std"); pub fn main() !void { var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; - const gpa = &general_purpose_allocator.allocator; + const gpa = general_purpose_allocator.getAllocator(); const args = try std.process.argsAlloc(gpa); defer std.process.argsFree(gpa, args); @@ -10842,7 +10842,7 @@ const PreopenList = std.fs.wasi.PreopenList; pub fn main() !void { var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; - const gpa = &general_purpose_allocator.allocator; + const gpa = general_purpose_allocator.getAllocator(); var preopens = PreopenList.init(gpa); defer preopens.deinit(); |
