Sorry for delay!
Ah, i think i know what the error might be. Zig removed a method I was using from the std, so I just put in a fix. Please pull the latest version of my template from Github!
I have not done any Lua programming on the Playdate unfortunately, but it looks like you would make C (or Zig functions, when using callconv(.C)
) available via Inside Playdate with C
So with regard to memory management, yes, you'd be using the heap for large-sized (or even medium-sized) data structures. The sole API Playdate has for this is realloc()
: Inside Playdate with C
So, when you need to allocate and free you'll call realloc(). On the face of it, the idea of manual memory management is that you allocate memory and use it, and then once you are done with it, you free it. It can be quite cumbersome to keep track of the objects you are done with and when to free them.
Luckily, that's not the end of the story. There are some nice techniques where you don't have to worry freeing every little allocation. Take a look at this series of articles by Ginger Bill (creator of the Odin programming language) about manual memory allocation: Memory Allocation Strategies - gingerBill Take note of arena allocators and free list allocators. There also videos on Youtube, especially about arena allocators.
In UPWARD, the workhorses are 3 arena allocators: one arena for global allocations that will last the entire game and is never freed, one arena that is reset every level, and one arena that is reset every frame. My arenas are preallocated by Playdate's realloc() API with a fixed size of memory.
https://github.com/DanB91/UPWARD-for-Playdate/blob/main/src/playdate_platform_main.zig#L63
I also use free lists for my doubly-linked list implementation.
I hope this is enough to get you started. Let me know if you have further questions!