Re: When to check the return value of malloc
- From: user923005 <dcorbit@xxxxxxxxx>
- Date: Tue, 22 Jan 2008 02:57:33 -0800 (PST)
On Jan 22, 2:05 am, "Malcolm McLean" <regniz...@xxxxxxxxxxxxxx> wrote:
"user923005" <dcor...@xxxxxxxxx> wrote in message
What happens if some other application (running at the same time as
your small RAM requestor) succeeds in getting RAM for video editing,
and then you ask for your small packet of RAM?
Not checking the return of malloc() is simply incompetent.
Assuming that something which can fail will always work is not a good
idea, and especially when checking is an ultra-simple operation.
BTW, 99.873% of all statistics about malloc() failure percentage are
made up out of thin air.
It depends if the video editor has deliberately tailored his request to the
amount of memory in the machine. If he has, all bets are off. If he hasn't,
then the chance of failing on the small packet rather than in the video
editor is quite small.
If you think the odds are quite small that other applications which
are not intentionally trying to allocate all of RAM can make your
malloc() fail are quite small, then I can assure you that you are
mistaken. It is not at all uncommon for people to run lots of
applications at the same time. Sometimes the applications are long-
running applications. Sometimes these applications have resource
leaks. Memory allocation failure for a large or small memory request
is not a rare occurence. I think it is very careless to assume that
any memory allocation will succeed without testing it.
.
- Follow-Ups:
- Re: When to check the return value of malloc
- From: CBFalconer
- Re: When to check the return value of malloc
- From: Malcolm McLean
- Re: When to check the return value of malloc
- References:
- When to check the return value of malloc
- From: Marty James
- Re: When to check the return value of malloc
- From: Malcolm McLean
- Re: When to check the return value of malloc
- From: Ulrich Eckhardt
- Re: When to check the return value of malloc
- From: Malcolm McLean
- Re: When to check the return value of malloc
- From: Ulrich Eckhardt
- Re: When to check the return value of malloc
- From: Malcolm McLean
- Re: When to check the return value of malloc
- From: Army1987
- Re: When to check the return value of malloc
- From: Malcolm McLean
- Re: When to check the return value of malloc
- From: Keith Thompson
- Re: When to check the return value of malloc
- From: Malcolm McLean
- Re: When to check the return value of malloc
- From: Keith Thompson
- Re: When to check the return value of malloc
- From: Malcolm McLean
- Re: When to check the return value of malloc
- From: Flash Gordon
- Re: When to check the return value of malloc
- From: Malcolm McLean
- Re: When to check the return value of malloc
- From: user923005
- Re: When to check the return value of malloc
- From: Malcolm McLean
- When to check the return value of malloc
- Prev by Date: Re: late night confusion with -> and .
- Next by Date: Re: linked list question
- 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
|