M
Mark McIntyre
CJ said:We were discussing implementing malloc(), in particular the following
situation.
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, so the program will crash with a SIGSEGV as
soon as the NULL pointer is dereferenced.
So why not just return a pointer to the 512Kb that's available?
Yike. Take this to the extreme. Imagine you only have one byte
available. Why not just return a pointer to that? How much use is /that/?
It's
quite possible that the user will never actually write into the upper
half of the memory he's allocated,
Its also quite possible the programmer knew how much memory he needed,
and will be justifiably annoyed when his programme starts randomly failing.