Re: Implementing Malloc()
Malcolm McLean wrote, On 26/11/07 23:27:
There is always something you can do without large runtime overheads.
You can always terminate the program. Of course, that is not always
acceptable.
If you design it without mechanisms for returning error conditions that
is true. However, if you design it properly it is not true.
Complete and utter rubbish. One is predictable and occurs at the actual
point of failure the other is not guaranteed.
Which it must be doing by checking the value returned by malloc. How can
you be claiming it produces an unacceptable overhead and then actually
doing it?
--
Flash Gordon
Malcolm McLean wrote, On 26/11/07 23:27:
>
"James Kuyper" <jameskuyper@ve rizon.netwrote in message
>>
>Only incompetent programmers who no sane person would hire would fail to
>check for malloc() failure. If that's a "huge majority", then the C
>programming world is in deep trouble.
>>
The problem is that, often, there is nothing you can do without imposing
unacceptable runtime overheads.
"James Kuyper" <jameskuyper@ve rizon.netwrote in message
>>Suppose the user requests 1Mb of memory. Unfortunately, we only have
>>512Kb available. In this situation, most mallocs() would return null.
>>The huge majority of programmers won't bother to check malloc() failure
>>for such a small allocation, ...
>>512Kb available. In this situation, most mallocs() would return null.
>>The huge majority of programmers won't bother to check malloc() failure
>>for such a small allocation, ...
>Only incompetent programmers who no sane person would hire would fail to
>check for malloc() failure. If that's a "huge majority", then the C
>programming world is in deep trouble.
>>
unacceptable runtime overheads.
You can always terminate the program. Of course, that is not always
acceptable.
This is especially true in windowing
systems where function that need to allocate trivial amounts of memory
are called by indirection, often several layers deep. It is no longer
possible to return an error condition to the caller.
systems where function that need to allocate trivial amounts of memory
are called by indirection, often several layers deep. It is no longer
possible to return an error condition to the caller.
is true. However, if you design it properly it is not true.
If all you cna do is exit(EXIT_FAILU RE); you might as well segfault, and
have more readable code.
have more readable code.
point of failure the other is not guaranteed.
That's why I introduced xmalloc(), the malloc() that never fails. It
achieves this by nagging for memory, until killed by the user as a last
resort when the cupboard is bare.
achieves this by nagging for memory, until killed by the user as a last
resort when the cupboard is bare.
you be claiming it produces an unacceptable overhead and then actually
doing it?
--
Flash Gordon
Comment