HPX memory calloc error - returns NULL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pervinder

    #1

    HPX memory calloc error - returns NULL

    Hi,
    I have a c applicaiton which uses calloc to allocate the storage from
    heap.
    A page is allocated (4096bytes) and then its used in smal small chunks
    on need.

    It works fine till some n number of pages are alloacted and used. But
    it fails
    to allocate a fresh page of 4096 after some m times when the prev.
    block gets exhausted and new block needs to be allocated/reserved.

    result = (alloc_list *) calloc((size_t) ASIZE, 1));
    The result becomes NULL... (ASIZE is 4096)
    Ran purify and it gave a MAF (Memory allocation Failure)

    Any hints as how to go about this issue ?

    I have a hp machine with limit as :-
    $::home> limit
    cputime 0:0-1
    filesize 4194303 kbytes
    datasize 2883584 kbytes
    stacksize 262144 kbytes
    coredumpsize 0 kbytes
    memoryuse 4194303 kbytes
    descriptors 200

    Regards, ~Pervinder
  • Jens.Toerring@physik.fu-berlin.de

    #2
    Re: HPX memory calloc error - returns NULL

    pervinder <pervinder@gmai l.com> wrote:[color=blue]
    > I have a c applicaiton which uses calloc to allocate the storage from
    > heap.
    > A page is allocated (4096bytes) and then its used in smal small chunks
    > on need.[/color]
    [color=blue]
    > It works fine till some n number of pages are alloacted and used. But
    > it fails
    > to allocate a fresh page of 4096 after some m times when the prev.
    > block gets exhausted and new block needs to be allocated/reserved.[/color]
    [color=blue]
    > result = (alloc_list *) calloc((size_t) ASIZE, 1));[/color]

    Casting the return value of (c|m|re)alloc() is superfluous and
    only will keep the compiler from complaining if you forgot to
    include <stdlib.h>.
    [color=blue]
    > The result becomes NULL... (ASIZE is 4096)[/color]

    calloc() (or malloc() or realloc()) returning NULL is completely
    legitimate - it means the system can't or won't give you anymore
    memory. Why it won't give you more depends on lots of system
    specific stuff - you may have reached some system-imposed limits,
    limits set for your processes, or you may already be using up all
    memory there is etc. - so you will have to ask in a group dedicated
    to your system or perhaps comp.unix.progr ammer.
    [color=blue]
    > I have a hp machine with limit as :-
    > $::home> limit
    > cputime 0:0-1
    > filesize 4194303 kbytes
    > datasize 2883584 kbytes
    > stacksize 262144 kbytes
    > coredumpsize 0 kbytes
    > memoryuse 4194303 kbytes
    > descriptors 200[/color]

    But even there your printout of the limits will be useless unless
    you also tell after how many allocations it fails - if 'datasize'
    stands for the upper limit of memory your program is allowed to
    use it wouldn't be a surprise if calloc() fails after about 720,000
    allocations, but things would probably be different if it fails
    after only say 5 (assuming that you really have several GB of
    (virtual) memory and the above numbers aren't due to an unrea-
    sonable setting of the limits).
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ Jens.Toerring@p hysik.fu-berlin.de
    \______________ ____________ http://www.toerring.de

    Comment

    • Jack Klein

      #3
      Re: HPX memory calloc error - returns NULL

      On 13 Dec 2004 13:38:42 GMT, Jens.Toerring@p hysik.fu-berlin.de wrote
      in comp.lang.c:
      [color=blue]
      > pervinder <pervinder@gmai l.com> wrote:[color=green]
      > > I have a c applicaiton which uses calloc to allocate the storage from
      > > heap.
      > > A page is allocated (4096bytes) and then its used in smal small chunks
      > > on need.[/color]
      >[color=green]
      > > It works fine till some n number of pages are alloacted and used. But
      > > it fails
      > > to allocate a fresh page of 4096 after some m times when the prev.
      > > block gets exhausted and new block needs to be allocated/reserved.[/color]
      >[color=green]
      > > result = (alloc_list *) calloc((size_t) ASIZE, 1));[/color]
      >
      > Casting the return value of (c|m|re)alloc() is superfluous and
      > only will keep the compiler from complaining if you forgot to
      > include <stdlib.h>.[/color]

      ....as is casting either of the arguments to size_t. In this
      particular case, if there is no prototype in scope, casting ASIZE to
      size_t is particularly useless, as the literal 1 will be passed as an
      int. And an int cannot possible be a size_t.

      --
      Jack Klein
      Home: http://JK-Technology.Com
      FAQs for
      comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
      comp.lang.c++ http://www.parashift.com/c++-faq-lite/
      alt.comp.lang.l earn.c-c++

      Comment

      • pervinder@gmail.com

        #4
        Re: HPX memory calloc error - returns NULL

        The 'n' is large but total memory allocated till the failure
        instant using calloc and malloc calls is ~250 Mb and the
        peak memory usage reported byt the executable after
        failure is 733 Mb

        Since the system has enogh memory (maxdsize 3G) so i
        think the issue here is not the memory allocation but its
        somewhat different. May be some hp system specific
        seting are limiting the same..
        -Pervinder

        Comment

        • pervinder

          #5
          Re: HPX memory calloc error - returns NULL

          The issue looks more of a hpx system imposed limits.
          I tried to allocate chunks of 128Kb till program runs out of memory
          And when i run the code on hpux, it goes out of memory after
          allocating a 767Mb from heap..
          -Pervinder

          Comment

          • pervinder

            #6
            Re: HPX memory calloc error - returns NULL

            I used chatr and executable worked fine
            $ chatr +q3p enable <ExeName>
            Please comment...
            -Pervinder

            Comment

            • Jens.Toerring@physik.fu-berlin.de

              #7
              Re: HPX memory calloc error - returns NULL

              pervinder <pervinder@gmai l.com> wrote:[color=blue]
              > I used chatr and executable worked fine
              > $ chatr +q3p enable <ExeName>
              > Please comment...[/color]

              No, not here since that has nothing to do with C - and you're
              posting to comp.lang.c and not comp.solving.hp .ux.problems or
              whatever. Go to a group where this is on-topic.

              Regards, Jens
              --
              \ Jens Thoms Toerring ___ Jens.Toerring@p hysik.fu-berlin.de
              \______________ ____________ http://www.toerring.de

              Comment

              • CBFalconer

                #8
                Re: HPX memory calloc error - returns NULL

                pervinder wrote:[color=blue]
                >
                > I used chatr and executable worked fine
                > $ chatr +q3p enable <ExeName>
                > Please comment...[/color]

                Allright. I have no idea what a chatr is, nor the vaguest idea
                what, if anything, you are talking about. With the total lack of
                context it could be anything. However I highly suspect it is
                off-topic here. I suggest you learn how to use newsgroups.

                --
                Chuck F (cbfalconer@yah oo.com) (cbfalconer@wor ldnet.att.net)
                Available for consulting/temporary embedded and systems.
                <http://cbfalconer.home .att.net> USE worldnet address!

                Comment

                Working...