diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-02-03 16:13:28 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-02-03 16:13:28 -0500 |
| commit | dfbc063f79dc1358208216b466c1bf8c44baa430 (patch) | |
| tree | 219c5f46a2e688fc1799117a1680102528691ce3 /std/heap.zig | |
| parent | c90c256868a80cd35e9ba679ba082330592620c9 (diff) | |
| download | zig-dfbc063f79dc1358208216b466c1bf8c44baa430.tar.gz zig-dfbc063f79dc1358208216b466c1bf8c44baa430.zip | |
`std.mem.Allocator.create` replaced with better API
`std.mem.Allocator.createOne` is renamed to `std.mem.Allocator.create`.
The problem with the previous API is that even after copy elision,
the initalization value passed as a parameter would always be a copy.
With the new API, once copy elision is done, initialization
functions can directly initialize allocated memory in place.
Related:
* #1872
* #1873
Diffstat (limited to 'std/heap.zig')
| -rw-r--r-- | std/heap.zig | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/std/heap.zig b/std/heap.zig index 46b247fa7e..fd2ce1e965 100644 --- a/std/heap.zig +++ b/std/heap.zig @@ -518,7 +518,8 @@ fn testAllocator(allocator: *mem.Allocator) !void { var slice = try allocator.alloc(*i32, 100); assert(slice.len == 100); for (slice) |*item, i| { - item.* = try allocator.create(@intCast(i32, i)); + item.* = try allocator.create(i32); + item.*.* = @intCast(i32, i); } slice = try allocator.realloc(*i32, slice, 20000); |
