Use a more appropriate allocator for level buffer.

Switched from General Purpous to Arena allocator.
This commit is contained in:
KikooDX 2021-01-26 23:38:41 +01:00
parent d07a3cd145
commit cf65e74492
2 changed files with 7 additions and 13 deletions

View File

@ -68,14 +68,11 @@ pub fn draw(self: *Self, offset: Vec2) void {
test "create level buffer" {
// Create allocator.
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer {
const leaked = gpa.deinit();
if (leaked) expect(false); //fail test
}
const allocator = &gpa.allocator;
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = &arena.allocator;
// Initialize level struct (twice 'cause why not?).
// Initialize level struct and allocate space (twice 'cause why not?).
var level: Self = try Self.init(allocator, 64, 32);
level.deinit(allocator);
level = try Self.init(allocator, 64, 64);

View File

@ -11,12 +11,9 @@ const Vec2 = @import("vec2.zig");
pub fn main() !void {
// Create allocator
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer {
const leaked: bool = gpa.deinit();
if (leaked) assert(false); //raise error
}
const allocator = &gpa.allocator;
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = &arena.allocator;
// Create window.
ray.SetConfigFlags(ray.FLAG_WINDOW_RESIZABLE);