Comment by flohofwoe

Comment by flohofwoe 8 days ago

1 reply

It's also a bad idea within the same language.

A C library returning a pointer to allocated memory and then expecting the caller to free that memory with a function outside the library (like calling stdlib free()) is just bad API design (because you can't and shouldn't need to know whether the library is actually using the stdlib alloc functions under the hood - or whether the library has been linked with the same C stdlib than your own code - for instance when the library resides in a DLL, or the library might decide to bypass malloc and directly use lower-level OS calls for allocating memory).

If you have a 'create' function in a C library, also always have a matching 'destroy' function.

On top of that it's also usually a good idea to let the library user override things like memory allocation or file IO functions.

...and of course 'general purpose' global allocators are a bad idea to begin with :)

filmor 8 days ago

That is exactly what what the parent post proposed.