Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

toOwnedSlice

Public Function
std.array_list.AlignedManaged.toOwnedSlice
pub fn toOwnedSlice(self: *Self) Allocator.Error!Slice

The caller owns the returned memory. Empties this ArrayList. Its capacity is cleared, making deinit safe but unnecessary to call. May invalidate element pointers if remapping memory cannot be done in place.

Params

File

array_list.zig:130
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
        pub fn toOwnedSlice(self: *Self) Allocator.Error!Slice {
            self.pointer_stability.assertUnlocked();
            const allocator = self.allocator;

            const old_memory = self.allocatedSlice();
            if (allocator.remap(old_memory, self.items.len)) |new_items| {
                self.* = init(allocator);
                return new_items;
            }

            const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);
            @memcpy(new_memory, self.items);
            self.clearAndFree();
            return new_memory;
        }