Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   malloc (http://www.go4expert.com/forums/malloc-t7736/)

harimagic 6Dec2007 13:46

malloc
 
Hi,

I have one doubt may be so many guys answer this.
We know that malloc use to allocate dynamic memory. But while writing programs we use to check with NULL.

Char *p;
p=(char *)malloc(100);
If(p==NULL)printf(“mem alloction failed”);// <-----(When dynamic allocation fail)

1. When will memory allocation fail?
2. I have a scenario that it should not be fail at any cost for that what I should do?

Salem 6Dec2007 15:11

Re: malloc
 
> 1. When will memory allocation fail?
Typically when you run out of memory, or the pool has become too fragmented that no large blocks remain.

> 2. I have a scenario that it should not be fail at any cost for that what I should do?
So you're writing a safety critical system in C?


All times are GMT +5.5. The time now is 05:14.