Lameguy64 / PSn00bSDK

The most powerful open source SDK for the PS1 (as far as open source PS1 SDKs go). Not recommended for beginner use.
Other
819 stars 66 forks source link

No realloc in libc #49

Closed Rufis01 closed 1 year ago

Rufis01 commented 2 years ago

As per title, realloc is not implemented. It'd be nice, since malloc->memcpy->free can be way less efficient.

spicyjpeg commented 2 years ago

I have been rewriting some parts of the SDK in C (fixing several bugs along the way) and the standard library is what I am working on right now. I'm probably going to implement realloc() as part of my rewrite, however you should not rely on it for anything other than shrinking allocated buffers as memory copying is particularly slow on the PS1. The default allocator is very simple, it's only meant to be used as a "master allocator" of sorts for a set of smaller, manually managed memory pools tailored to specific use cases. You should not expect much from it in terms of performance or efficiency.

Also keep in mind that malloc() and free() are declared as weak functions, so you can override them and the rest of the SDK will use your custom allocator.

spicyjpeg commented 2 years ago

@Rufis01: I have finally replaced the old allocator and added realloc() to my psxmdec branch. I'm going to open a PR once a few other things (i.e. string library improvements, a slightly faster Huffman decoder implementation and a video playback example) are in place, but you can already use my fork in the meantime.

spicyjpeg commented 1 year ago

realloc() has been available in the master branch since v0.20 so I'm closing this issue.