malloc() and limitations

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

    malloc() and limitations

    I am using malloc to allocation memory for a group of structures. I am
    not using a whole lot of memory.
    But my program can run without a problem on a machine with 2GB RAM, but
    with a machine less than 1GB memory, it fails to allocate memory.

    What are the reasons the system cannot allocate memory? How can I fix
    this problem?
    ( when the program starts, I am only using about 40MB memory which is
    not a whole lot)

    Please help me if you have any ideas

  • pghoshjobs@gmail.com

    #2
    Re: malloc() and limitations


    questions? wrote:
    I am using malloc to allocation memory for a group of structures. I am
    not using a whole lot of memory.
    But my program can run without a problem on a machine with 2GB RAM, but
    with a machine less than 1GB memory, it fails to allocate memory.
    >
    What are the reasons the system cannot allocate memory? How can I fix
    this problem?
    ( when the program starts, I am only using about 40MB memory which is
    not a whole lot)
    >
    Please help me if you have any ideas
    you would not be able to allocate memory more then your physical memory
    space. possibly the other programs are occupying the rest of the
    memory. check out the available free memory using the 'free' command.


    - Partha

    Comment

    • Keith Thompson

      #3
      Re: malloc() and limitations

      "questions? " <universal_used @hotmail.comwri tes:
      I am using malloc to allocation memory for a group of structures. I am
      not using a whole lot of memory. But my program can run without a
      problem on a machine with 2GB RAM, but with a machine less than 1GB
      memory, it fails to allocate memory.
      >
      What are the reasons the system cannot allocate memory? How can I fix
      this problem? ( when the program starts, I am only using about 40MB
      memory which is not a whole lot)
      The amount of memory that your program is allowed to allocate depends
      on the operating system. It's very likely that the limit is going to
      be far less than the total amount of memory on the system.

      The details are implementation-specific. You might try asking in a
      newsgroup that's specific to your system. <OT>If you're on a
      Unix-like system, look into "limit" and/or "ulimit"; on other systems,
      I haven't a clue.</OT>

      --
      Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
      San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
      We must do something. This is something. Therefore, we must do this.

      Comment

      • ffairy2323@yahoo.com

        #4
        Re: malloc() and limitations

        use reference point...


        regards
        <a href=www.gamest otal.com>free</a>
        <a href=http://unificationwars .xeepo.com/>online</a>
        <a href=http://unificationwars .0catch.com/>online games</a>

        Comment

        • ffairy2323@yahoo.com

          #5
          Re: malloc() and limitations

          use reference point...


          regards
          <a href=www.gamest otal.com>free</a>
          <a href=http://unificationwars .xeepo.com/>online</a>
          <a href=http://unificationwars .0catch.com/>online games</a>

          Comment

          • Keith Thompson

            #6
            Re: malloc() and limitations

            pghoshjobs@gmai l.com writes:
            questions? wrote:
            >I am using malloc to allocation memory for a group of structures. I am
            >not using a whole lot of memory.
            >But my program can run without a problem on a machine with 2GB RAM, but
            >with a machine less than 1GB memory, it fails to allocate memory.
            >>
            >What are the reasons the system cannot allocate memory? How can I fix
            >this problem?
            >( when the program starts, I am only using about 40MB memory which is
            >not a whole lot)
            >>
            >Please help me if you have any ideas
            >
            you would not be able to allocate memory more then your physical memory
            space. possibly the other programs are occupying the rest of the
            memory. check out the available free memory using the 'free' command.
            Not all systems have a "free" command. (In fact, I don't know of any
            that do.)

            --
            Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
            San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
            We must do something. This is something. Therefore, we must do this.

            Comment

            • goose

              #7
              Re: malloc() and limitations

              questions? wrote:
              I am using malloc to allocation memory for a group of structures. I am
              not using a whole lot of memory.
              But my program can run without a problem on a machine with 2GB RAM, but
              with a machine less than 1GB memory, it fails to allocate memory.
              >
              What are the reasons the system cannot allocate memory? How can I fix
              this problem?
              ( when the program starts, I am only using about 40MB memory which is
              not a whole lot)
              >
              Please help me if you have any ideas
              My guess is that there is an error in your code.
              Perhaps you've miscalculated and did something like
              the following:

              int sizes[] = {10, 20, 30};
              ....
              ptr = malloc (sizes[4]); /* using garbage value, UB, etc */

              Or maybe you did something like this
              int length;
              ....
              ptr = malloc (length); /* length uninitialised */


              Or you may have even done this
              int length = 0;
              ....
              ptr = malloc (length); /* implementation defined,
              can return NULL */


              Whichever it is, I seriously doubt that any small
              program that manipulates a group of structures
              can legitimately exhaust memory on a 1G ram
              implementation. If you are dealing with such large
              amounts of data you are either:
              a) reading it from disk and therefore you know how
              large it is on disk (is it really supposed to be
              a gig?) and should not be surprised when you run
              out of memory.
              b) you are generating the data yourself, which should
              take a tremendous amount of time for non-trivial
              algorithms to fill up a gig.

              So, please post the smallest compilable code that
              causes this problem and perhaps we can spot the
              problem.

              If you are generating the data from an algorithm,
              a short description of the algorithm would be nice
              too.

              goose,

              Comment

              • Stephen Sprunk

                #8
                Re: malloc() and limitations

                "Keith Thompson" <kst-u@mib.orgwrote in message
                news:lny7ti389t .fsf@nuthaus.mi b.org...
                "questions? " <universal_used @hotmail.comwri tes:
                >I am using malloc to allocation memory for a group of structures. I
                >am
                >not using a whole lot of memory. But my program can run without a
                >problem on a machine with 2GB RAM, but with a machine less than 1GB
                >memory, it fails to allocate memory.
                >>
                >What are the reasons the system cannot allocate memory? How can I fix
                >this problem? ( when the program starts, I am only using about 40MB
                >memory which is not a whole lot)
                >
                The amount of memory that your program is allowed to allocate depends
                on the operating system. It's very likely that the limit is going to
                be far less than the total amount of memory on the system.
                OTOH, many implementations allow you to allocate far _more_ than the
                amount of physical memory. My system has a paltry 512MB of RAM yet user
                processes can allocate just shy of 2GB _each_ -- though the system gets
                rather slow if you actually try to _use_ that much.

                S

                --
                Stephen Sprunk "God does not play dice." --Albert Einstein
                CCIE #3723 "God is an inveterate gambler, and He throws the
                K5SSS dice at every possible opportunity." --Stephen Hawking



                --
                Posted via a free Usenet account from http://www.teranews.com

                Comment

                • Gordon Burditt

                  #9
                  Re: malloc() and limitations

                  >What are the reasons the system cannot allocate memory? How can I fix
                  >this problem?
                  >( when the program starts, I am only using about 40MB memory which is
                  >not a whole lot)
                  >>
                  >Please help me if you have any ideas
                  >
                  >you would not be able to allocate memory more then your physical memory
                  >space.
                  There are a lot of virtual-memory systems which allow this (assuming
                  you're not counting swap/page space as "physical memory"). You may
                  have to override administrative defaults. You may or may not pay
                  a huge performance penalty which can still be better than the even
                  worse penalty of not being able to run it at all.

                  Gordon L. Burditt

                  Comment

                  • Keith Thompson

                    #10
                    Re: malloc() and limitations

                    gordonb.3wmjt@b urditt.org (Gordon Burditt) writes:
                    >>What are the reasons the system cannot allocate memory? How can I fix
                    >>this problem?
                    >>( when the program starts, I am only using about 40MB memory which is
                    >>not a whole lot)
                    >>>
                    >>Please help me if you have any ideas
                    The above was posted by "questions? " <universal_used @hotmail.com>.
                    >>you would not be able to allocate memory more then your physical memory
                    >>space.
                    The above was posted by pghoshjobs@gmai l.com.
                    There are a lot of virtual-memory systems which allow this (assuming
                    you're not counting swap/page space as "physical memory"). You may
                    have to override administrative defaults. You may or may not pay
                    a huge performance penalty which can still be better than the even
                    worse penalty of not being able to run it at all.
                    The above was posted by Gordon Burditt, who continues to insist on
                    deleting attribution lines in his followups. This is, as always,
                    extraordinarily rude.

                    --
                    Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                    San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
                    We must do something. This is something. Therefore, we must do this.

                    Comment

                    Working...