Re: automatic vs allocated attempts
- From: Eric Sosman <esosman@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 04 Jan 2010 16:00:47 -0500
On 1/4/2010 3:41 PM, Richard Bos wrote:
ram@xxxxxxxxxxxxxxxxxx (Stefan Ram) wrote:
Why does C have this asymmetry between automatic and
allocated storage?
Why is it ok to code in C as if allocations of automatic
storage will never fail, but not ok to code as if
allocations of allocated storage will never fail, when
in fact both might fail?
Hysterical raisins, I presume. That is, it must have been assumed (and
was, AFAIK, common practice in pre-existing languages) that local
storage would only or predominantly be used for small objects (a handful
of single ints, floats or pointers) while static, global or allocated
storage would be used for large arrays and whole blocks of memory.
It's also the case that the mechanisms for detecting and
reporting (and maybe recovering from) exhaustion of automatic
memory are highly system-specific, varying rather widely from
one environment to the next. Even on a single machine, the
mechanisms available to hosted "user-land" code are usually
different from those applicable in free-standing "kernel" code.
That makes it difficult for a programming language to legislate
one particular way of handling the condition.
malloc(), on the other hand, is not really a creature of
the "core language," but of the library. It can report failure
as a function value -- the fact that functions can return values
is in no way a "special mechanism" just for memory management.
The details of detecting dynamic memory exhaustion can be hidden
safely inside the malloc() implementation, without putting a
structural burden on the rest of the language.
Even so, some implementations get malloc() arguably wrong.
"OOM pa-pa, OOM pa-pa, that's 'ow it goes ..."
--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxxx
.
- References:
- Re: automatic vs allocated attempts
- From: Richard Bos
- Re: automatic vs allocated attempts
- Prev by Date: Re: defining a boolean type
- Next by Date: Re: automatic vs allocated attempts
- Previous by thread: Re: automatic vs allocated attempts
- Next by thread: Re: automatic vs allocated attempts
- Index(es):
Relevant Pages
|