Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. malloc limitations

malloc limitations

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
8 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rupeshkp728
    wrote on last edited by
    #1

    We know that in a 32 bit system a 4 gb memory gets allocated to a process. So how much maximum memory can be allocated using a malloc function call?

    N D A 3 Replies Last reply
    0
    • R rupeshkp728

      We know that in a 32 bit system a 4 gb memory gets allocated to a process. So how much maximum memory can be allocated using a malloc function call?

      N Offline
      N Offline
      Niklas L
      wrote on last edited by
      #2

      That depends on what OS you will be using.

      home

      R 1 Reply Last reply
      0
      • N Niklas L

        That depends on what OS you will be using.

        home

        R Offline
        R Offline
        rupeshkp728
        wrote on last edited by
        #3

        Thanks Niklas for the inputs If suppose I am using a 32 bit windows or linux OS then what will be the limit?

        N 1 Reply Last reply
        0
        • R rupeshkp728

          We know that in a 32 bit system a 4 gb memory gets allocated to a process. So how much maximum memory can be allocated using a malloc function call?

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          rupeshkp728 wrote:

          We know that in a 32 bit system a 4 gb memory gets allocated to a process.

          It's 2GB unless the /3GB startup switch is used.

          rupeshkp728 wrote:

          So how much maximum memory can be allocated using a malloc function call?

          Since it has to be contiguous, no more than 2GB, but realistically it will be less.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Man who follows car will be exhausted." - Confucius

          R 1 Reply Last reply
          0
          • D David Crow

            rupeshkp728 wrote:

            We know that in a 32 bit system a 4 gb memory gets allocated to a process.

            It's 2GB unless the /3GB startup switch is used.

            rupeshkp728 wrote:

            So how much maximum memory can be allocated using a malloc function call?

            Since it has to be contiguous, no more than 2GB, but realistically it will be less.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "Man who follows car will be exhausted." - Confucius

            R Offline
            R Offline
            rupeshkp728
            wrote on last edited by
            #5

            Thanks David for the solution

            1 Reply Last reply
            0
            • R rupeshkp728

              Thanks Niklas for the inputs If suppose I am using a 32 bit windows or linux OS then what will be the limit?

              N Offline
              N Offline
              Naveen
              wrote on last edited by
              #6

              Again it depends on the OS. In window, usually a process can take only 2GB of memory( User mode ), the remaining 2GB is reserved for Kernal mode. Again among this 2GB, some memory will be already taken by process, for loading exe, dll, heap, stack etc. So technically, the maximum about of memory that you can specify in malloc is always less than 2GB and the excat value depends on various factors I mentioned above. I dont know about Linux :(

              nave [My Articles] [My Blog]

              1 Reply Last reply
              0
              • R rupeshkp728

                We know that in a 32 bit system a 4 gb memory gets allocated to a process. So how much maximum memory can be allocated using a malloc function call?

                A Offline
                A Offline
                Aescleal
                wrote on last edited by
                #7

                That's a bit like asking "how long is a piece of string?" Here's why... - Every process is given it's own address space to run in. Depending on where the OS and compiler conspire to load your code will determine the largest lump of memory you can allocate - The OS may allocated loads of other guff which will restrict where the compiler can stick it's heap - The OS may have extra overheads managing it's heap (e.g. Windows having different heaps for different size ranges of allocation) - How malloc is implemented on top of the underlying OS can also mess things up - The computer may not have enough disk space or memory to service your request So to find out how much you can allocate try it! Do a malloc for INT_MAX bytes and if that fails divide the size by 2 and try again. You can use something a bit more sophisticated but you really need to try it on a particular system with a given compiler and load to see what happens. Cheers, Ash

                R 1 Reply Last reply
                0
                • A Aescleal

                  That's a bit like asking "how long is a piece of string?" Here's why... - Every process is given it's own address space to run in. Depending on where the OS and compiler conspire to load your code will determine the largest lump of memory you can allocate - The OS may allocated loads of other guff which will restrict where the compiler can stick it's heap - The OS may have extra overheads managing it's heap (e.g. Windows having different heaps for different size ranges of allocation) - How malloc is implemented on top of the underlying OS can also mess things up - The computer may not have enough disk space or memory to service your request So to find out how much you can allocate try it! Do a malloc for INT_MAX bytes and if that fails divide the size by 2 and try again. You can use something a bit more sophisticated but you really need to try it on a particular system with a given compiler and load to see what happens. Cheers, Ash

                  R Offline
                  R Offline
                  rupeshkp728
                  wrote on last edited by
                  #8

                  Thanks Ash for the reply. I tried malloc with INT_MAX and it indeed fails and with your way we can find out how much exactly the memory can be allocated.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups