| ... | ... | @@ -105,6 +105,20 @@ pub const Allocator = struct { |
| 105 | 105 | return self.alignedAlloc(T, null, n); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | /// Allocates an array of `n + 1` items of type `T` and sets the first `n` |
| 109 | /// items to `undefined` and the last item to `sentinel`. Depending on the |
| 110 | /// Allocator implementation, it may be required to call `free` once the |
| 111 | /// memory is no longer needed, to avoid a resource leak. If the |
| 112 | /// `Allocator` implementation is unknown, then correct code will |
| 113 | /// call `free` when done. |
| 114 | /// |
| 115 | /// For allocating a single item, see `create`. |
| 116 | pub fn allocSentinel(self: *Allocator, comptime Elem: type, n: usize, comptime sentinel: Elem) Error![:sentinel]Elem { |
| 117 | var ptr = try self.alloc(Elem, n + 1); |
| 118 | ptr[n] = sentinel; |
| 119 | return ptr[0 .. n :sentinel]; |
| 120 | } |
| 121 | |
| 108 | 122 | pub fn alignedAlloc( |
| 109 | 123 | self: *Allocator, |
| 110 | 124 | comptime T: type, |