Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Eric <nospam@nospam.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Failing Malloc |
| Date | 2012-09-13 20:21 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <k2tf88$ki9$1@speranza.aioe.org> (permalink) |
| References | <k2qq2i$aba$1@speranza.aioe.org> <L864s.41309$Ax.33657@fx18.am4> <k2qrlc$ea5$1@speranza.aioe.org> <e95d81dd-908d-42cb-bdd2-893456fe16f3@e29g2000vbm.googlegroups.com> |
On Wed, 12 Sep 2012 13:46:51 -0700, Paul N wrote:
> On Sep 12, 9:34 pm, Eric <nos...@nospam.com> wrote:
>> On Wed, 12 Sep 2012 21:21:02 +0100, Andrew Cooper wrote:
>> > On 12/09/2012 21:07, Eric wrote:
>> >> Hi What is a good way to respond to a failed Malloc (returns Null)?
>> >> I do not want to call Abort or Exit immediately.
>>
>> >> Thanks
>>
>> > Well - you should probably try to flush any files which are open,
>> > return eternal changes back to defaults (changes to the terminal
>> > etc), and find a way of letting your user see, or at least work out
>> > why they no longer have a running process.
>>
>> > Failing gracefully is a lot more effort than you might imagine at
>> > first.
>>
>> Sorry maybe I wasn't too clear. I would like to get the Malloc call to
>> succeed if I redo it. Or get some alternative memory eg from the stack
>> or swop.
>
> If your program has an alternative way of working which uses less memory
> (say, for example, a slower method) you could put in a new malloc asking
> for less memory and see if that works. Or you could allocate more memory
> than you need early in the program, so you've got a bit already to hand
> when you run a crucial bit of the program. Or you could tell the user
> that unfortunately the program can't do what was requested.
>
> Getting more memory from the stack seems a little risky, as there are
> normally less checks whether it worked. Swapping your own program's data
> out to disk might be a possibility if you keep track of what you have
> done. Swapping other programs out to disk is system-specific, if you
> want to try this then other newsgroups will be able to give better help.
What I mean is, imagine a very large allocation say 4MB. Maybe that's not
available in one chunk, however 4 seperate 1MB allocations could succeed.
That sort of thing.
By stack I mean essentially a local array, i.e.
func()
{
char buf[1000]; /* <--- example */
/* buf can never be Null */
}
Note, that in this case, Null can never be returned for the array.
Thanks
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Failing Malloc Eric <nospam@nospam.com> - 2012-09-12 20:07 +0000
Re: Failing Malloc Xavier Roche <xroche@free.fr.NOSPAM.invalid> - 2012-09-12 22:12 +0200
Re: Failing Malloc William Ahern <william@wilbur.25thandClement.com> - 2012-09-12 14:25 -0700
Re: Failing Malloc Andrew Cooper <andrew@nospam.example.com> - 2012-09-12 21:21 +0100
Re: Failing Malloc Eric <nospam@nospam.com> - 2012-09-12 20:34 +0000
Re: Failing Malloc Paul N <gw7rib@aol.com> - 2012-09-12 13:46 -0700
Re: Failing Malloc Eric <nospam@nospam.com> - 2012-09-13 20:21 +0000
Re: Failing Malloc Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-13 17:31 -0400
Re: Failing Malloc James Kuyper <jameskuyper@verizon.net> - 2012-09-13 17:57 -0400
Re: Failing Malloc John Gordon <gordon@panix.com> - 2012-09-12 20:55 +0000
Re: Failing Malloc William Ahern <william@wilbur.25thandClement.com> - 2012-09-12 14:33 -0700
Re: Failing Malloc falk@rahul.net (Edward A. Falk) - 2012-09-13 22:43 +0000
Re: Failing Malloc James Kuyper <jameskuyper@verizon.net> - 2012-09-12 17:37 -0400
Re: Failing Malloc Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-09-13 08:57 +0200
Re: Failing Malloc James Kuyper <jameskuyper@verizon.net> - 2012-09-12 17:20 -0400
Re: Failing Malloc Ian Collins <ian-news@hotmail.com> - 2012-09-13 09:27 +1200
Re: Failing Malloc James Kuyper <jameskuyper@verizon.net> - 2012-09-12 17:56 -0400
Re: Failing Malloc Ian Collins <ian-news@hotmail.com> - 2012-09-13 10:28 +1200
Re: Failing Malloc James Kuyper <jameskuyper@verizon.net> - 2012-09-12 18:57 -0400
Re: Failing Malloc William Ahern <william@wilbur.25thandClement.com> - 2012-09-12 16:21 -0700
Re: Failing Malloc Ian Collins <ian-news@hotmail.com> - 2012-09-13 12:07 +1200
Re: Failing Malloc James Kuyper <jameskuyper@verizon.net> - 2012-09-13 13:18 -0400
Re: Failing Malloc Ian Collins <ian-news@hotmail.com> - 2012-09-14 07:37 +1200
Re: Failing Malloc James Kuyper <jameskuyper@verizon.net> - 2012-09-13 16:05 -0400
Re: Failing Malloc William Ahern <william@wilbur.25thandClement.com> - 2012-09-13 14:21 -0700
Re: Failing Malloc James Kuyper <jameskuyper@verizon.net> - 2012-09-13 17:38 -0400
Re: Failing Malloc William Ahern <william@wilbur.25thandClement.com> - 2012-09-13 14:03 -0700
Re: Failing Malloc Ian Collins <ian-news@hotmail.com> - 2012-09-15 10:01 +1200
Re: Failing Malloc Philip Lantz <prl@canterey.us> - 2012-09-14 02:50 -0700
Re: Failing Malloc Kaz Kylheku <kaz@kylheku.com> - 2012-09-12 21:36 +0000
Re: Failing Malloc Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-12 17:41 -0400
Re: Failing Malloc Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-09-12 16:07 -0600
Re: Failing Malloc "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-09-12 16:03 -0700
Re: Failing Malloc Kenneth Brody <kenbrody@spamcop.net> - 2012-09-12 19:24 -0400
Re: Failing Malloc The Great Firewall of China Blue <chine.bleu@yahoo.com> - 2012-09-12 16:34 -0700
Re: Failing Malloc Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-09-13 00:14 -0700
csiph-web