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 exact number of bytes accessible in RAM for a 32 Bit app?

how to get exact number of bytes accessible in RAM for a 32 Bit app?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
9 Posts 4 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.
  • D Offline
    D Offline
    Divya Rathore
    wrote on last edited by
    #1

    Is there a function available that can return the Maximum number of bytes accessible in RAM for a 32 Bit App? It might be running on either 32 or 64 Bit machines. I know of the flag /LARGEADDRESSAWARE. What I am specifically looking for is a function that can tell me the number of bytes as numeric quantity.

    C L 3 Replies Last reply
    0
    • D Divya Rathore

      Is there a function available that can return the Maximum number of bytes accessible in RAM for a 32 Bit App? It might be running on either 32 or 64 Bit machines. I know of the flag /LARGEADDRESSAWARE. What I am specifically looking for is a function that can tell me the number of bytes as numeric quantity.

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

      Try GlobalMemoryStatusEx[^] maybe.

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<

      1 Reply Last reply
      0
      • D Divya Rathore

        Is there a function available that can return the Maximum number of bytes accessible in RAM for a 32 Bit App? It might be running on either 32 or 64 Bit machines. I know of the flag /LARGEADDRESSAWARE. What I am specifically looking for is a function that can tell me the number of bytes as numeric quantity.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Hi Divya, The maximum virtual address can be determined by doing something like:

        SYSTEM_INFO si = {0};
        GetSystemInfo(&si);
        DWORD_PTR dwMaximumAddress = (DWORD_PTR)si.lpMaximumApplicationAddress;

        If you wanted to determine if the physical address extensions are enabled on a 32 bit OS you could then do something like:

        BOOL bPAE = ((DWORD_PTR)si.lpMaximumApplicationAddress >= 0xBFFFFFFF);

        Best Wishes, -David Delaune

        D 1 Reply Last reply
        0
        • D Divya Rathore

          Is there a function available that can return the Maximum number of bytes accessible in RAM for a 32 Bit App? It might be running on either 32 or 64 Bit machines. I know of the flag /LARGEADDRESSAWARE. What I am specifically looking for is a function that can tell me the number of bytes as numeric quantity.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          As mentioned, GetSysInfo() will give you the physical memory, but then you have to ask yourself why you want to know this since half of this is physically reserved for the kernel, but the virtual memory each process runs in will be addressable memory up to 4 GB regardless of what you have physically. So, what are you trying to do and why?

          ============================== Nothing to say.

          D 1 Reply Last reply
          0
          • L Lost User

            Hi Divya, The maximum virtual address can be determined by doing something like:

            SYSTEM_INFO si = {0};
            GetSystemInfo(&si);
            DWORD_PTR dwMaximumAddress = (DWORD_PTR)si.lpMaximumApplicationAddress;

            If you wanted to determine if the physical address extensions are enabled on a 32 bit OS you could then do something like:

            BOOL bPAE = ((DWORD_PTR)si.lpMaximumApplicationAddress >= 0xBFFFFFFF);

            Best Wishes, -David Delaune

            D Offline
            D Offline
            Divya Rathore
            wrote on last edited by
            #5

            Thanks a ton, David! I will try to figure out what to do with those details.

            R 1 Reply Last reply
            0
            • L Lost User

              As mentioned, GetSysInfo() will give you the physical memory, but then you have to ask yourself why you want to know this since half of this is physically reserved for the kernel, but the virtual memory each process runs in will be addressable memory up to 4 GB regardless of what you have physically. So, what are you trying to do and why?

              ============================== Nothing to say.

              D Offline
              D Offline
              Divya Rathore
              wrote on last edited by
              #6

              Eric, what I am trying to find is 'guess-timate' (I finally found an occasion to use this word) the amount of memory available to my application (a rather loose statement, I know.. but hopefully gives the idea). An algorithm in the app that needs quite a lot of memory would need to know if that memory is available or not. Its a dedicated app, there is little chance of some other app requesting a large chunk of memory in parallel. The memory the algorithm will use is known (or can be approximately figured out based on the input data). So I was hoping that these 2 numbers (available memory and needed memory) would help in a quick decision making as to whether we should proceed with the processing or not. thanks for the reply!

              L C 2 Replies Last reply
              0
              • D Divya Rathore

                Eric, what I am trying to find is 'guess-timate' (I finally found an occasion to use this word) the amount of memory available to my application (a rather loose statement, I know.. but hopefully gives the idea). An algorithm in the app that needs quite a lot of memory would need to know if that memory is available or not. Its a dedicated app, there is little chance of some other app requesting a large chunk of memory in parallel. The memory the algorithm will use is known (or can be approximately figured out based on the input data). So I was hoping that these 2 numbers (available memory and needed memory) would help in a quick decision making as to whether we should proceed with the processing or not. thanks for the reply!

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                OK, so in fact you can allocate a massive chunk of memory, because the system will page it out for you if it cant physically fit in RAM. (It will page it out in pages, 4k chunks, so you might want to organise your memory usage so commonly used stuff is on the same page(s) in order to keep it resident in memory)

                ============================== Nothing to say.

                1 Reply Last reply
                0
                • D Divya Rathore

                  Eric, what I am trying to find is 'guess-timate' (I finally found an occasion to use this word) the amount of memory available to my application (a rather loose statement, I know.. but hopefully gives the idea). An algorithm in the app that needs quite a lot of memory would need to know if that memory is available or not. Its a dedicated app, there is little chance of some other app requesting a large chunk of memory in parallel. The memory the algorithm will use is known (or can be approximately figured out based on the input data). So I was hoping that these 2 numbers (available memory and needed memory) would help in a quick decision making as to whether we should proceed with the processing or not. thanks for the reply!

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

                  Also note that "available memory" != "biggest continous block you can allocate". What i mean is something like this: [1 MB of free memory][2 MB of already allocated memory][3 MB of free memory] If you query the amount of free memory, you get 4 MB, if you try to allocate a 4 MB block, it will fail because the biggest continous free chunk is only 3MB. I'm just sayinmg because we ran into this already once or twice... :)

                  > The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<

                  1 Reply Last reply
                  0
                  • D Divya Rathore

                    Thanks a ton, David! I will try to figure out what to do with those details.

                    R Offline
                    R Offline
                    Rajesh R Subramanian
                    wrote on last edited by
                    #9

                    Divya, marking his reply as answer will help others know that it's a good answer and that it helped you. I've marked it now, and you can too.

                    "Real men drive manual transmission" - Rajesh.

                    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