Add common memory functions to pd_api.h

,

While working with C it is quite common to use malloc, calloc, free, realloc. Currently, the only function exposed for working with memory is realloc, leaving it up to the developer to reimplement these familiar memory functions.

I propose we add these functions to their respective places next to realloc.

Another reason this would be helpful is when the developer implements these functions, they must register them with the current playdate instance, a step that could result in error if done at the incorrect time. I implemented exactly these functions in order to bridge the gap till then.

Removing the initialization step would be awesome!

1 Like

Someone on the forums, or maybe on the non-official Discord channel, wrote some macros to simulate most of the libc alloc functions based on realloc(). I'm sorry I don't remember the link.

2 Likes

Ok I found the previously mentioned macro implementation.

1 Like

Ah nice, quite similar but no registration step. Smart!

Interestingly, I have not been able to get this to work. Missing symbols.

Edit: figured this out, was placing the pd in wrong location. just added to pd_api.h

Just had a big aha moment regarding this. Looks like we'll be able to let you use the normal libc functions after all: C API malloc hassle

1 Like