Arena is a grower now
This commit is contained in:
parent
724fd5ed4f
commit
720fd7f7ed
|
@ -24,9 +24,13 @@ ArenaAllocator := struct {
|
||||||
log.debug("deinit: allocator")
|
log.debug("deinit: allocator")
|
||||||
}
|
}
|
||||||
alloc := fn(self: ^Self, $T: type, count: uint): ?^T {
|
alloc := fn(self: ^Self, $T: type, count: uint): ?^T {
|
||||||
if count * @sizeof(T) + self.allocated > self.size {
|
if self.allocated + count * @sizeof(T) > self.size {
|
||||||
log.error("You allocated more memory on the arena than the arena had.");
|
ptr := Target.realloc(self.ptr, self.size, self.size * 2)
|
||||||
die
|
if ptr == null {
|
||||||
|
log.error("Failed to grow arena");
|
||||||
|
die
|
||||||
|
}
|
||||||
|
self.ptr = @unwrap(ptr)
|
||||||
}
|
}
|
||||||
allocation := self.ptr + self.allocated
|
allocation := self.ptr + self.allocated
|
||||||
self.allocated = self.allocated + count * @sizeof(T)
|
self.allocated = self.allocated + count * @sizeof(T)
|
||||||
|
@ -55,4 +59,4 @@ ArenaAllocator := struct {
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue