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. How to get physical memory size available to a process?

How to get physical memory size available to a process?

Scheduled Pinned Locked Moved C / C++ / MFC
helpvisual-studiocomsalesperformance
5 Posts 2 Posters 0 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.
  • C Offline
    C Offline
    Code o mat
    wrote on last edited by
    #1

    Hello folks! I used GlobalMemoryStatusEx[^] to get memory information. As the subject suggests, i am looking for the available physical memory my process may allocate, however, the ullAvailPhys member of MEMORYSTATUSEX[^] shows all the available memory bytes, not only the bytes allocatable by my process. So you understand, windows has a 2Gb (i know this can be increased to 3Gb but that's of no relevance right now) limit per process. So if my computer has 3Gb memory, my process allocates 1.5Gb, then i check the free memory size, i get 1.5G, but if i try to allocate that 1.5G, it will fail since only 0.5G is available to my process. I might be wrong, i am not sure, so please correct me if i am. So i figured, if i take the smaller value of ullAvailPhys and ullAvailVirtual, this should give me the available physical mem for my process, but this is really a guess. So...can someone tell me how to do this correctly, or if this way is reliable? Thanks for any info in advance.

    > The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <

    N 1 Reply Last reply
    0
    • C Code o mat

      Hello folks! I used GlobalMemoryStatusEx[^] to get memory information. As the subject suggests, i am looking for the available physical memory my process may allocate, however, the ullAvailPhys member of MEMORYSTATUSEX[^] shows all the available memory bytes, not only the bytes allocatable by my process. So you understand, windows has a 2Gb (i know this can be increased to 3Gb but that's of no relevance right now) limit per process. So if my computer has 3Gb memory, my process allocates 1.5Gb, then i check the free memory size, i get 1.5G, but if i try to allocate that 1.5G, it will fail since only 0.5G is available to my process. I might be wrong, i am not sure, so please correct me if i am. So i figured, if i take the smaller value of ullAvailPhys and ullAvailVirtual, this should give me the available physical mem for my process, but this is really a guess. So...can someone tell me how to do this correctly, or if this way is reliable? Thanks for any info in advance.

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <

      N Offline
      N Offline
      norish
      wrote on last edited by
      #2

      Which API did you call to allocate memory?

      C 1 Reply Last reply
      0
      • N norish

        Which API did you call to allocate memory?

        C Offline
        C Offline
        Code o mat
        wrote on last edited by
        #3

        Well, the "default" implementation of new and malloc are mostly used for memory allocation as far as i know (what memory allocators 3rd party codes and windows API calls use is beyond me).

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <

        N 1 Reply Last reply
        0
        • C Code o mat

          Well, the "default" implementation of new and malloc are mostly used for memory allocation as far as i know (what memory allocators 3rd party codes and windows API calls use is beyond me).

          > The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <

          N Offline
          N Offline
          norish
          wrote on last edited by
          #4

          Default implementation of new of vc is malloc and malloc calls VirtualAlloc. I checked how much memory's can be allocated on my pc with XP SP3. Available Phys. Memory: 1.7GB (from task manager) Available Virtual Memory: 2.0GB (from GlobalMemoryStatusEx) My program allocated: 1.5GB (by VirtualAlloc or malloc) My program's Total Virtual Size: 1.5GB (from task manager) In general, total virtual memory space 2GB is sum of program own code size, some resources and other crt dll space size. So in this case, my program's size without heap should be around 500MB. (I think this strange.) I guess some other programs (like a anti virus program or so) or some Windows settings affected to this situation.

          C 1 Reply Last reply
          0
          • N norish

            Default implementation of new of vc is malloc and malloc calls VirtualAlloc. I checked how much memory's can be allocated on my pc with XP SP3. Available Phys. Memory: 1.7GB (from task manager) Available Virtual Memory: 2.0GB (from GlobalMemoryStatusEx) My program allocated: 1.5GB (by VirtualAlloc or malloc) My program's Total Virtual Size: 1.5GB (from task manager) In general, total virtual memory space 2GB is sum of program own code size, some resources and other crt dll space size. So in this case, my program's size without heap should be around 500MB. (I think this strange.) I guess some other programs (like a anti virus program or so) or some Windows settings affected to this situation.

            C Offline
            C Offline
            Code o mat
            wrote on last edited by
            #5

            Thanks but i don't see how this answers my question...please clearify and sorry for my ignorance.

            > The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <

            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