what do you do when malloc fails?

what do you do when malloc fails?

Post by Bernard Ch » Sat, 16 Oct 1993 10:27:29



This is a C question, but what should be done if a malloc call fails?
Right now I'm assuming that my program isn't going to use a whole lot
of memory, so I'm not too afraid of it happening.  What should be done
if the malloc call does fail though?  Right now, I just have my
program exit.  Is there a more graceful way of working around this?

bern

 
 
 

what do you do when malloc fails?

Post by David Nob » Sat, 16 Oct 1993 11:02:29



>This is a C question, but what should be done if a malloc call fails?
>Right now I'm assuming that my program isn't going to use a whole lot
>of memory, so I'm not too afraid of it happening.

Your program might not use much memory, but another program could use up so
much that there's none left for you. Better to scream "Outta Memory!" than
to mysteriously dump core, especially if the low-memory condition is caused
by some other unrelated program.

Quote:>What should be done if the malloc call does fail though?  Right now,
>I just have my program exit.  Is there a more graceful way of working
>around this?

You could indicate that there's not enough memory, then pause a while and
retry the malloc() a few times. That would give a user the opportunity to
kill something off that's maybe not so important. Depends on how your
program is going to be used.

On the topic of low-memory conditions, is it just my imagination or does
IBM's RS/6000 assassinate processes when it gets really low on resources?

--


 
 
 

1. HELP: Connectivity between DOS/DOS and DOS/Linux

HI there,

In about march we should be getting a second PC in our house. I was
concidering trying to network the two machines. One of the machines
is going to be a DOS/Windows affair while the other one is hoping
to become a DOS and Linux setup. I have a few questions that I hope
that someone out there can answer. (The kind of network I'm concid-
ering is peer-to-peer, I think)

1) Using Novell Netware light on the DOS/Windows machine, could it
connect to the Linux machine using standard networking stuff? Would
I be able to have netware on my DOS partition of my Linux/DOS machine
so that when I boot it up using DOS I'm still connected?

2) If I were using the Linux front end for DOOM, could I still play
a multiplayer game across the network? Or would I have to go back to
DOS?

3) Just out of curiosity, could anyone give me info on cost. I've
got a home made estimate (made from various sources) of :



Cabling (roughly)                               :20
                                                ----
Total                                           136

This is a rough estimate, if anyone can confirm or deny this value
please set me straight.

Answers would be much appersiated as it will influence my decision
as to weather to get the network and/or to get Linux.

TTFN and TC, Michael Dales

-'Damn you and your networking problems Q!'-Picard

2. kswapd deadlock 2.4.3-pre6

3. DoS tmpfs,ramfs, malloc, saga continues

4. RTFM? But which FM?? How do I set up a PPP-Server?

5. Problems with malloc() when doing 64-bit

6. internal modem does not work

7. accessing dos partitions with wd7000fasst scsi, isc unix 2.2, dos[345]

8. xfs on RedHat 6.1 fails to start

9. Uninstall Linux: Deleted "non dos partition" with DOS fdisk -- Now what?!?

10. Samba w/ DOS box - what does DOS need?

11. Can I boot from DOS to use DOS Device Drivers?

12. Mini Linux coexists in DOS partition and boot from DOS

13. Q: Filenames turnicated DOS to LINUX to DOS?