More work on this
This commit is contained in:
parent
2418526e89
commit
b3fe6b4de8
src
|
@ -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 {
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
.{RawAllocator} := @use("raw.hb");
|
||||
.{SimpleAllocator} := @use("simple.hb")
|
||||
.{SimpleAllocator} := @use("simple.hb");
|
||||
.{ArenaAllocator} := @use("arena.hb");
|
||||
|
|
12
src/test/lily/lily.alloc.arena.hb
Normal file
12
src/test/lily/lily.alloc.arena.hb
Normal 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
|
||||
}
|
Loading…
Reference in a new issue