-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathallocator.zig
42 lines (30 loc) · 1016 Bytes
/
allocator.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//Shows a working example of allocation and freeing
const psp = @import("psp/utils/psp.zig");
const sysmem = @import("psp/include/pspsysmem.zig");
const std = @import("std");
const fmt = std.fmt;
comptime {
asm (psp.module_info("Zig PSP App", 0, 1, 0));
}
fn printFreeMem(alloc: *std.mem.Allocator) void {
var freeMem = sysmem.sceKernelTotalFreeMemSize();
const fMem = std.fmt.allocPrint(alloc, "{} Bytes Free\n", .{freeMem}) catch unreachable;
psp.debug.print(fMem);
alloc.free(fMem);
}
pub fn main() !void {
psp.utils.enableHBCB();
psp.debug.screenInit();
var psp_allocator = &psp.PSPAllocator.init().allocator;
printFreeMem(psp_allocator);
const string: []const u8 = try std.fmt.allocPrint(
psp_allocator,
"{} {} {}\n",
.{ "Hello", "from", "Zig!" },
);
psp.debug.print(string);
printFreeMem(psp_allocator);
psp_allocator.free(string); //Explicit free
printFreeMem(psp_allocator);
psp.debug.print("\nKTHXBYE!");
}