K
Kelsey Bjarnason
[snips]
Your malloc "replacement" is not easier to use than malloc; it is, in
fact, more difficult, as it lies about what it does, then fails to even
meet the details of the lie - and it does erroneous things with perfectly
legitimate allocation requests.
So, let's see. "it must not return NULL unless no memory is to be
found". Hmm. That would be malloc.
Easier to use? You just don't *get* much easier than malloc. To call it
usefully, you have to store the result into a pointer anyhow. Validation
of success is accomplished by a single if statement: it's just about
impossible to get simpler than that and still be useful.
And if nothing else, malloc doesn't lie about what it actually does, and
works on all legitimate size requests, if memory is, in fact, available
to meet the request.
I am not in any sense tied to the xmalloc() error-handling method. If
anyone can come up with a better idea, please post. It must not return
null unless no memory is to be found, and it must be easier for caller
to use than regular malloc().
Your malloc "replacement" is not easier to use than malloc; it is, in
fact, more difficult, as it lies about what it does, then fails to even
meet the details of the lie - and it does erroneous things with perfectly
legitimate allocation requests.
So, let's see. "it must not return NULL unless no memory is to be
found". Hmm. That would be malloc.
Easier to use? You just don't *get* much easier than malloc. To call it
usefully, you have to store the result into a pointer anyhow. Validation
of success is accomplished by a single if statement: it's just about
impossible to get simpler than that and still be useful.
And if nothing else, malloc doesn't lie about what it actually does, and
works on all legitimate size requests, if memory is, in fact, available
to meet the request.