Re: calloc fails and returns NULL

Discussion in 'C Programming' started by Keith Thompson, Nov 7, 2012.

  1. k2ibegining <> writes:
    > in one of our application's module, calloc() is failing and returning
    > NULL. The amount of memory that it is trying to allocate is of
    > structure which is of 9292 bytes. The operating system is AIX 7.1 and
    > running VIOS 2.2.1.3.
    >
    > The machine has 2+GB ram and does not seems to have an issue with lack
    > of memory. The same application module is running fine on one of the
    > other boxes, which has same configurations as the problematic
    > box.Following is a snippet of memory from both the boxes and they are
    > same !
    >

    [...]
    >
    > I'm clueless as can't really figure out why calloc() is failing even
    > for 9292 bytes on this box.


    I see you (I presume it was you) posted the same question on
    stackoverflow.com. I'll make the same comment I made there: Show
    us the code, including the call to calloc and the code that checks
    its result.

    And make sure that you're really passing the argument valuess you
    think you are.

    Also, though this probably isn't relevant to your problem, consider
    whether you really need to use calloc() rather than malloc().
    calloc(count, size) is equivalent to malloc(count * size) (assuming
    that count*size is representable as a size_t) except that calloc()
    initializes the allocated memory to zero. Do you really need that
    initialization?

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Will write code for food.
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Nov 7, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Philip Lantz

    Re: calloc fails and returns NULL

    Philip Lantz, Nov 7, 2012, in forum: C Programming
    Replies:
    0
    Views:
    216
    Philip Lantz
    Nov 7, 2012
  2. Ben Bacarisse

    Re: calloc fails and returns NULL

    Ben Bacarisse, Nov 7, 2012, in forum: C Programming
    Replies:
    0
    Views:
    268
    Ben Bacarisse
    Nov 7, 2012
  3. Greg Martin

    Re: calloc fails and returns NULL

    Greg Martin, Nov 7, 2012, in forum: C Programming
    Replies:
    0
    Views:
    206
    Greg Martin
    Nov 7, 2012
  4. Anand Hariharan

    Re: calloc fails and returns NULL

    Anand Hariharan, Nov 7, 2012, in forum: C Programming
    Replies:
    0
    Views:
    205
    Anand Hariharan
    Nov 7, 2012
  5. Ian Collins

    Re: calloc fails and returns NULL

    Ian Collins, Nov 8, 2012, in forum: C Programming
    Replies:
    0
    Views:
    261
    Ian Collins
    Nov 8, 2012
Loading...

Share This Page