init allocator in main

This commit is contained in:
Brendan Hansknecht 2024-07-25 18:42:34 -07:00
parent 7373a76f81
commit 52f6c30173
No known key found for this signature in database
GPG key ID: 0EA784685083E75B

View file

@ -1,7 +1,13 @@
const std = @import("std");
const sort = @import("sort.zig");
var gpa: std.heap.GeneralPurposeAllocator(.{}) = undefined;
var allocator: std.mem.Allocator = undefined;
pub fn main() !void {
gpa = .{};
allocator = gpa.allocator();
const size = 1000000;
var arr_ptr: [*]i64 = @alignCast(@ptrCast(testing_roc_alloc(size * @sizeOf(i64), @alignOf(i64))));
defer testing_roc_dealloc(arr_ptr, @alignOf(i64));
@ -48,9 +54,6 @@ comptime {
@export(testing_roc_panic, .{ .name = "roc_panic", .linkage = .Strong });
}
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
fn testing_roc_alloc(size: usize, _: u32) callconv(.C) ?*anyopaque {
// We store an extra usize which is the size of the full allocation.
const full_size = size + @sizeOf(usize);