Re: xmalloc string functions
- From: Kelsey Bjarnason <kbjarnason@xxxxxxxxx>
- Date: Sun, 27 Jan 2008 11:48:05 +0000
[snips]
On Sun, 27 Jan 2008 10:24:59 -0500, Eric Sosman wrote:
The specifications are too weak to drive implementations.
What does xmalloc() do when unable to allocate memory?
Calls an optionally-user-specified function to figure out how to free up
some memory (eg opening a window to say "Please close another
application", which, of course, assumes there's enough memory to do so),
or, failing that, aborts the application.
Yes, that's right, it's a trap door function: you can enter, but you can
never leave, unless and until the memory is available. No error
reporting, no recovery, no options at all. That is the intent of the
code, as Malcolm has expressed more than once, that you *cannot* recover
from any allocation failure. You get the memory, or you exit. Period.
Does replace()
replace all occurrences, or just the first, or just the last, or what?
What does getquote() do with unbalanced quotes?
And does it do single quotes? Double quotes? Both?
I've think we've got something quite powerful here, purely because none
of these functions can ever return null for out of memory conditions.
It massively simplifies string handling.
... and massively complicates error handling.
No, no, it makes error handling *easier*, because you don't ever need to
*do* error handling. xmalloc does that for you - by ensuring you get the
memory, or the app aborts. See how wonderful it is? No need for all
that error handling code at the calling point. Also no way to ever do
anything like, oh, reduce the allocation request and try again, or
reschedule the operation for later, etc, etc, etc, but hey, it's not like
any application would ever actually do things like that.
If xmalloc()
can unilaterally terminate the program
Not "can", by design it is *required to*, unless the allocation
succeeds. One or the other: you get the memory, or the app dies.
the whole suite is unusable
except in toy programs.
Except it's of little use in toy apps. Such an app probably doesn't do a
hell of a lot of complex allocations in the first place, so wouldn't
benefit significantly from "easy malloc". A complex app where there may
be thousands or millions of allocations done from hundreds or thousands
of places in the code, now this would benefit from "easy malloc" - if it
were actually useful.
The xmalloc notion presented is of little interest in a toy app, and is
unusable in a real app. One wonders where, exactly, it would actually be
used. One place it won't be used: my code. I actually like to be able
to choose a course of action on allocation failure, not be stuck with
some asinine notion that allocation will succeed or there's no point in
continuing.
.
- Follow-Ups:
- Re: xmalloc string functions
- From: Malcolm McLean
- Re: xmalloc string functions
- References:
- xmalloc string functions
- From: Malcolm McLean
- Re: xmalloc string functions
- From: Eric Sosman
- xmalloc string functions
- Prev by Date: Re: xmalloc string functions
- Next by Date: Re: Is Chris Hills a troll?
- Previous by thread: Re: xmalloc string functions
- Next by thread: Re: xmalloc string functions
- Index(es):
Relevant Pages
|