2024-02-27 10:58:05 -06:00

24 lines
685 B
Plaintext

const std = #import("std");
const Error = error{
unexpected_result,
};
const main = fn() Error!void {
const size = 0x1000;
if (std.page_allocator.allocate(size, alignment = 12)) |result| {
result[0] = 0;
std.print(bytes = "Allocation succeeded. Freeing...\n");
if (std.page_allocator.free(bytes_ptr = result.ptr, bytes_len = result.len)) {
std.print(bytes = "Memory freed successfully\n");
} else {
std.print(bytes = "Memory freed with errors\n");
return Error.unexpected_result;
}
} else {
std.print(bytes = "Allocation failed!\n");
return Error.unexpected_result;
}
}