authorgravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-09-27 18:54:43-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-27 21:54:43-04:00
log583ca36e62fc13b38348f9c42bbfb9ddd9fceaa0
tree7add58c241ba443082caafda836c2d21d3779abc
parentc03a76414717274d02280fdaaaceff1ef4151d07

add reset() method to IncrementingAllocator (#501)


1 files changed, 4 insertions(+), 0 deletions(-)

std/mem.zig+4
...@@ -94,6 +94,10 @@ pub const IncrementingAllocator = struct {...@@ -94,6 +94,10 @@ pub const IncrementingAllocator = struct {
94 _ = os.posix.munmap(self.bytes.ptr, self.bytes.len);94 _ = os.posix.munmap(self.bytes.ptr, self.bytes.len);
95 }95 }
9696
97 fn reset(self: &IncrementingAllocator) {
98 self.end_index = 0;
99 }
100
97 fn alloc(allocator: &Allocator, n: usize, alignment: usize) -> %[]u8 {101 fn alloc(allocator: &Allocator, n: usize, alignment: usize) -> %[]u8 {
98 const self = @fieldParentPtr(IncrementingAllocator, "allocator", allocator);102 const self = @fieldParentPtr(IncrementingAllocator, "allocator", allocator);
99 const addr = @ptrToInt(&self.bytes[self.end_index]);103 const addr = @ptrToInt(&self.bytes[self.end_index]);