Richard Heathfield said:
Ed Jensen said:
In most applications, information comes in via streams and goes out via
streams, a lot (otherwise where are you getting your data and where are
you putting the results?). But nobody is bothering to propose a "solution
for the read/write failures problem" (and rightly so, because there isn't
such a problem). The fact that malloc is called a lot is not an excuse for
calling it badly.
Memory is subtly different from other resources.
Let's say there arises a requirement to find the shortest path through a
maze. We are not sure whether this is computable in reasonable time or not,
but we are confident enough to commit to writing a function that finds "a
short path" and executes in reasonable time.
Since we don't have the function, we can define an interface. Then we work
out the shortest path for a few test cases by hand, and we've got a plugin
that works on the test cases, and gives the developers of the rest of the
program something to play with.
Now does our algorithm require dynamic memory or not? Can it return an out
of memory fail condition?
What about the callers of the function. Can they return OOM fail conditions
or not?
Maybe we'd better say that the algorithm does use dynamic memory, even if at
the end of the day it does not, just to be on the safe side.
Memory is different from all other resources.