I am trying to use ArrayList more in my w.i.p game. I found the documentation of clearRetainingCapacity confusing, so looked up the source (both in Zig 0.14.1 and current 0.15 dev head):
/// Invalidates all element pointers.
pub fn clearRetainingCapacity(self: *Self) void {
self.items.len = 0;
}
/// Invalidates all element pointers.
pub fn clearAndFree(self: *Self) void {
self.allocator.free(self.allocatedSlice());
self.items.len = 0;
self.capacity = 0;
}
First of, the documentation is identical for these two, and they are clearly doing differnt things.
For my use case, I am not using pointers for the elements, but (small) structs and wanted to re-use an ArrayList over and over in the main loop of my game, only freeing the array after exiting the main loop, so I guess clearRetainingCapacity is the one I want?