J
Joachim Schmitz
Ulrich Eckhardt wrote:
so the overhead would be that of a function call, no big deal.
free() has to take anything malloc() might return, that includes NULL and
malloc(0) is explictly allowed, and allthough it does have an implementation
defined behavoir, there are two choices allowed and choking on it is not
amongst them.
Bye, Jojo
Well, any decent implementation will do that _first thing inside_ malloc(),In that light, I'd even say that xmalloc should start like this:
if(s==0)
return NULL;
void* p=malloc(s);
...
The simple rationale is that dynamic allocations are typically
expensive, so avoiding them is worthwhile.
so the overhead would be that of a function call, no big deal.
Neither is allowed to a conforming implementation.There is one caveat though: IIRC, quite a few implementations choke on
free(NULL), even more than those that choke on malloc(0).
free() has to take anything malloc() might return, that includes NULL and
malloc(0) is explictly allowed, and allthough it does have an implementation
defined behavoir, there are two choices allowed and choking on it is not
amongst them.
Bye, Jojo