1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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