| ... | @@ -633,6 +633,17 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -633,6 +633,17 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 633 | return self; | 633 | return self; |
| 634 | } | 634 | } |
| 635 | | 635 | |
| | 636 | /// Initialize with externally-managed memory. The buffer determines the |
| | 637 | /// capacity, and the length is set to zero. |
| | 638 | /// When initialized this way, all methods that accept an Allocator |
| | 639 | /// argument are illegal to call. |
| | 640 | pub fn initBuffer(buffer: Slice) Self { |
| | 641 | return .{ |
| | 642 | .items = buffer[0..0], |
| | 643 | .capacity = buffer.len, |
| | 644 | }; |
| | 645 | } |
| | 646 | |
| 636 | /// Release all allocated memory. | 647 | /// Release all allocated memory. |
| 637 | pub fn deinit(self: *Self, allocator: Allocator) void { | 648 | pub fn deinit(self: *Self, allocator: Allocator) void { |
| 638 | allocator.free(self.allocatedSlice()); | 649 | allocator.free(self.allocatedSlice()); |