malloc

Discussion in 'C' started by harimagic, Dec 6, 2007.

  1. harimagic

    harimagic New Member

    Joined:
    Oct 5, 2007
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    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?
     
  2. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    > 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?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice