Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: recalloc |
| Date | 2015-06-21 19:28 +0100 |
| Organization | go, ion artisan! |
| Message-ID | <mm6vm7$ndv$1@dont-email.me> (permalink) |
| References | <mm5lnh$tna$1@dont-email.me> <6cb341d1-ae2d-4521-8f9b-21a6adcc14d9@googlegroups.com> |
On 21/06/15 18:14, Malcolm McLean wrote:
<snip>
> The real problem with realloc() is the temp dance you need to clean
> up in the event of an allocation failure.
Hi, Malcolm. Wonderful weather we're having, how's the family, etc etc,
and NO, that is not the real problem with realloc.
Here's why. Consider malloc:
/* allocate memory */
p = malloc(n * sizeof *p);
if(p != NULL)
{
use it
}
else
{
handle the failure
}
Now consider realloc:
t = realloc(p, new_n * sizeof *t);
if(t != NULL)
{
p = t;
n = new_n;
use it
}
else
{
handle the failure
}
Only two extra lines of code, both easy ones, and you get the awesome
functionality of realloc. How is that a "problem" that realloc has,
that, say, malloc or calloc don't have?
No, the real problem with realloc is the same as with malloc and calloc
- people don't check the return value or, if they do, they consider
bombing out to be a sane and viable programming strategy, which is quite
possibly why my browser crashes when I try to open the nth tab (for
unpredictable values of n).
--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
recalloc jacobnavia <jacob@jacob.remcomp.fr> - 2015-06-21 08:32 +0200
Re: recalloc luser droog <luser.droog@gmail.com> - 2015-06-20 23:43 -0700
Re: recalloc Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-21 10:00 +0100
Re: recalloc luser droog <luser.droog@gmail.com> - 2015-06-21 09:57 -0700
Re: recalloc Richard Heathfield <rjh@cpax.org.uk> - 2015-06-21 07:51 +0100
Re: recalloc jacobnavia <jacob@jacob.remcomp.fr> - 2015-06-21 09:22 +0200
Re: recalloc Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-21 09:49 +0100
Re: recalloc jacobnavia <jacob@jacob.remcomp.fr> - 2015-06-21 12:00 +0200
Re: recalloc Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-21 12:46 +0100
Re: recalloc James Kuyper <jameskuyper@verizon.net> - 2015-06-21 12:25 -0400
Re: recalloc David Kleinecke <dkleinecke@gmail.com> - 2015-06-22 08:27 -0700
Re: recalloc James Kuyper <jameskuyper@verizon.net> - 2015-06-21 12:30 -0400
Re: recalloc Keith Thompson <kst-u@mib.org> - 2015-06-21 13:00 -0700
Re: recalloc Keith Thompson <kst-u@mib.org> - 2015-06-21 12:44 -0700
Re: recalloc jacobnavia <jacob@jacob.remcomp.fr> - 2015-06-21 10:30 +0200
Re: recalloc Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-06-21 10:14 -0700
Re: recalloc Richard Heathfield <rjh@cpax.org.uk> - 2015-06-21 19:28 +0100
Re: recalloc Bartc <bc@freeuk.com> - 2015-06-21 20:10 +0100
Re: recalloc Keith Thompson <kst-u@mib.org> - 2015-06-21 12:46 -0700
Re: recalloc Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-06-21 13:41 -0700
Re: recalloc Richard Heathfield <rjh@cpax.org.uk> - 2015-06-22 00:02 +0100
Re: recalloc jacobnavia <jacob@jacob.remcomp.fr> - 2015-06-21 22:59 +0200
Re: recalloc Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-06-21 14:18 -0700
Re: recalloc Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-11 04:50 -0700
Re: recalloc jacobnavia <jacob@jacob.remcomp.fr> - 2015-07-11 16:18 +0200
Re: recalloc Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-11 13:51 -0700
Re: recalloc jacobnavia <jacob@jacob.remcomp.fr> - 2015-07-12 15:51 +0200
Re: recalloc Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-15 03:57 -0700
csiph-web