std.ArrayList: make unmanaged the default

This commit is contained in:
Andrew Kelley
2025-07-31 21:54:07 -07:00
parent d625158354
commit 749f10af49
161 changed files with 861 additions and 870 deletions

View File

@@ -6241,9 +6241,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
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
their initialization functions:
allocate accept an {#syntax#}Allocator{#endsyntax#} parameter. Likewise, some data structures
accept an {#syntax#}Allocator{#endsyntax#} parameter in their initialization functions:
</p>
{#code|test_allocator.zig#}

View File

@@ -1,7 +1,7 @@
const std = @import("std");
test "detect leak" {
var list = std.ArrayList(u21).init(std.testing.allocator);
var list = std.array_list.Managed(u21).init(std.testing.allocator);
// missing `defer list.deinit();`
try list.append('☔');