David King writes:

> On-topic from <http://ubuntuforums.org/showthread.php?t=612606>:
>
> I'm interested in audio, so I'm looking over the (frankly horrible)
> documentation for this new "Pulse Audio" thing, and I see this
> function in its shared lib:
>
>     pa_xmalloc()
>     Allocates the specified number of bytes, just like malloc() does.
>     However, in case of OOM, terminate.
>
> First of all, why are so many programmers who write a Linux shared
> library offering a simple wrapper function around malloc? Is it too
> hard for an app to just call malloc? Is anyone so completely absent- 
> minded that he can't remember malloc is used to allocate memory, so
> he needs an equivalent wrapper in every shared lib he uses?

The system version of malloc() is often Not Elite Enough for your
enlightened library authors -- q.v. glib, which apparently wants to
use its own allocator for some pretty sketchy reasons.

Alternatively, the system allocator(s) is/are Too Damn Broken to work
reliably in the various permutations of DLL Hell -- q.v. Windows --
and calling free() on a pointer that another DLL malloc()'ed can crash
your application or silently corrupt the heap.  (I wish I were joking
about this.)

That all depends on how portable you want your library API to be, but
I agree on the folly of exporting a function that terminates the
application on failure.

Michael Poole

Reply via email to