>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?
--