More work on this

This commit is contained in:
Talha Qamar 2025-01-31 22:28:13 +05:00
parent 2418526e89
commit b3fe6b4de8
3 changed files with 20 additions and 11 deletions
src

View file

@ -10,15 +10,11 @@ ArenaAllocator := struct {
size: uint,
allocated: uint,
$new := fn(size: uint): Self {
allocated := idk
if size == 0 {
allocated = Target.page_size()
} else {
allocated = size
}
ptr := Target.alloc_zeroed(size)
return .(ptr, size, 0)
$new := fn(): Self {
allocated := 0
allocated = Target.page_size()
ptr := Target.alloc_zeroed(allocated)
return .(ptr, allocated, 0)
}
deinit := fn(self: ^Self): void {
match Target.current() {
@ -37,7 +33,7 @@ ArenaAllocator := struct {
log.debug("allocated")
return @bitcast(allocation)
}
alloc_zeroed := fn(self: ^Self, $T: type, count: uint): ?^T {
$alloc_zeroed := fn(self: ^Self, $T: type, count: uint): ?^T {
return self.alloc(T, count)
}
realloc := fn(self: ^Self, $T: type, ptr: ^T, count: uint): ?^T {

View file

@ -1,2 +1,3 @@
.{RawAllocator} := @use("raw.hb");
.{SimpleAllocator} := @use("simple.hb")
.{SimpleAllocator} := @use("simple.hb");
.{ArenaAllocator} := @use("arena.hb");

View file

@ -0,0 +1,12 @@
/*
* exit: 0
*/
lily := @use("../../lily/lib.hb")
main := fn(argc: int, argv: [][]u8): u8 {
alloc := lily.alloc.ArenaAllocator.new()
ptr_one := alloc.alloc(u8, 6)
ptr_two := alloc.alloc(u8, 179)
alloc.deinit()
return 0
}