Re: When to check the return value of malloc
- From: David Thompson <dave.thompson2@xxxxxxxxxxx>
- Date: Mon, 28 Jan 2008 04:12:11 GMT
On Fri, 18 Jan 2008 22:39:24 -0500, CBFalconer <cbfalconer@xxxxxxxxx>
wrote:
Randy Howard wrote:
Eric Sosman wrote
Apparently this is some strange new value of 20 * 20 of which I was"Obviously," you can allocate an infinite amount of
memory as long as you get it in 20-byte chunks? Did you
used to work for Enron or something?
This thread was useful, now I know I never have to buy extra
memory again.
PROVIDED you malloc it in 20 byte chunks. Since the standard
specifies that freed memory be made available again, you must be
perfectly safe in allocating 4k by:
for (i = 0; i < 20; i++) a[i] = malloc(20);
for (i = 0; i < 20; i++) free(a[i]);
ptr = malloc(4000);
with suitable declarations for a, i, ptr, and all the needed
#includes. Learning is wunnerful.
previously unaware.
(I know it's a joke, but cf. Twain on lightning != lightningbug.)
<G>
- formerly david.thompson1 || achar(64) || worldnet.att.net
.
- References:
- When to check the return value of malloc
- From: Marty James
- Re: When to check the return value of malloc
- From: Eric Sosman
- Re: When to check the return value of malloc
- From: Randy Howard
- Re: When to check the return value of malloc
- From: CBFalconer
- When to check the return value of malloc
- Prev by Date: Re: The machine stack and the C language
- Next by Date: Re: xmalloc string functions
- Previous by thread: Re: When to check the return value of malloc
- Next by thread: Re: When to check the return value of malloc
- Index(es):
Relevant Pages
|