Compare commits

..

No commits in common. "0ee8b7a4e4a26addb7db06830732528e7fdefe37" and "6f82c92c309a0f21374cce323119e26f86678735" have entirely different histories.

View file

@ -1,4 +1,4 @@
.{log, panic} := @use("../lib.hb") .{log} := @use("../lib.hb")
alloc_return := @use("alloc_return.hb") alloc_return := @use("alloc_return.hb")
/* the block size is 64 bytes, 64 blocks of 64 bytes. /* the block size is 64 bytes, 64 blocks of 64 bytes.
@ -13,11 +13,11 @@ BlockAlloc := struct {
return .(0, null) return .(0, null)
} }
alloc := fn(self: Self, alloc_type: type, count: uint): alloc_return.AllocReturn { $alloc := fn(self: Self, alloc_type: type, count: uint): alloc_return.AllocReturn {
offset := 1 offset := 1
a := 1 a := 1
loop { loop {
// a = self.state >> offset // a = self.state >> offset;
// check if the `offset` bit is 1, if it is move to the next offset // check if the `offset` bit is 1, if it is move to the next offset
if a == 1 { if a == 1 {
offset += 1 offset += 1
@ -26,12 +26,7 @@ BlockAlloc := struct {
// self it to 1 and return the ptr to the allocation // self it to 1 and return the ptr to the allocation
self.state |= a self.state |= a
// return ptr + offset * 64 // return ptr + offset * 64
if self.ptr != null {
return .(64, self.ptr + offset * 64) return .(64, self.ptr + offset * 64)
} else {
// panic.panic("Allocator is not inited.\0")
// return .(0, null)
}
} }
// there are only 64 blocks // there are only 64 blocks
if offset >= 64 { if offset >= 64 {
@ -40,7 +35,7 @@ BlockAlloc := struct {
} }
} }
dealloc := fn(self: Self, ptr: ^u8, alloc_type: type, count: uint): void { $dealloc := fn(self: Self, ptr: ^u8, alloc_type: type, count: uint): void {
// size := size_of(alloc_type)*count // size := size_of(alloc_type)*count
size := 64 size := 64
// get the size alligned to the nearest block // get the size alligned to the nearest block