Is err-string from `playdate->file->geterr` should be deallocated or not?

,

I forget, should that err-string be deallocated or not?

char* playdate->file->geterr(void); (doc)

I suppose that if there are rendered strings like "file {name} not found", so it should be freed. But also there are static strings too. So :man_shrugging:t2:.

It's marked const which means no, you shouldn't free it. The compiler will give you a warning, hopefully a hard error, if you try to pass it to free() or assign it to a non-const char*

1 Like

Thanks! How long I can wait and then read valid string from that ptr? Is it static location?

I know that doc pointing that it could be overwritten by any next FS-operation, so string (and length to null) could be changed, but the location? It that pointer still will be valid after future FS-ops?

The whole point of an API is that the implementation can change as long as the contract stays the same. It might be a pointer to an internal static buffer now but I'm allowed to change it to a heap allocation later because if you've written your code correctly not relying on that implementation detail it'll work either way. The only safe thing to do if you need that data later is to copy it to a buffer you own.

2 Likes

Thanks, I’ve got it. Currently I doing it so. But just thinking about optimization, because I copy into heap every time.