chore: remove all memory leaks

This commit is contained in:
2022-01-03 20:08:55 -06:00
parent 8257a3899a
commit 3aa680ab8c
6 changed files with 37 additions and 1 deletions

View File

@@ -10,17 +10,27 @@ pub const Ppu = struct {
.vram = try Vram.init(alloc),
};
}
pub fn deinit(self: *@This()) void {
self.vram.deinit();
}
};
const Vram = struct {
buf: []u8,
alloc: Allocator,
fn init(alloc: Allocator) !@This() {
return @This(){
.buf = try alloc.alloc(u8, 0x18000),
.alloc = alloc,
};
}
fn deinit(self: *@This()) void {
self.alloc.free(self.buf);
}
pub inline fn get32(self: *const @This(), idx: usize) u32 {
return (@as(u32, self.buf[idx + 3]) << 24) | (@as(u32, self.buf[idx + 2]) << 16) | (@as(u32, self.buf[idx + 1]) << 8) | (@as(u32, self.buf[idx]));
}