locked
How do i get the ram size of a computer? RRS feed

  • Question

  • I'm developing a tool that can use the ram as a storage device and store files in it. I need to get the ram size of that computer to calculate the max size of files that can be stored. How can i get the ram size? (i'm using visual c++ 2010)
    • Moved by edhickey Tuesday, June 28, 2011 9:41 PM (From:.NET 4: Windows Workflow Foundation)
    Tuesday, June 28, 2011 7:36 PM

Answers

  • I hadn't considered paging at all! :( I'll need to think about that. I guess if I use a little less memory than  what's freely available, it won't be paged?

    I don't think that is a safe bet.  Unfortunately we don't have much control over what is paged and what isn't.  And even if the RAM were free now you have very little control that some other process (or even Windows kernel/driver) won't want some of that physical RAM later.

    If you have a couple of hours to spend learning the basics, I highly recommend Mark Russinovich's "Mysteries of Windows Memory Management"  (both parts). It will at least let you know what the right questions to ask are.  Selvam has some good suggestions as to the APIs you might use, but as it sounds like your app may actually care about some of the subtleties that most of us can ignore, I would recommend the videos so you can understand the differences between all the types of memory.

    • Marked as answer by Rob Pan Monday, July 4, 2011 2:24 AM
    Wednesday, June 29, 2011 1:47 PM

All replies

  • Tricky question. 

    Do you want the physical memory on the computer (keeping in mind that if your PC has 4 GB and you use 4 GB in your app, there is near certainty that some of it will have been paged out to disk)? 

    Do you want user address space (2 or 3 GB for a 32 bit app, much larger in 64 bit app)?

    The largest block of contiguous memory you could allocate?  Total memory you could allocate? (keeping in mind that paging to disk could occur for either of these)

     

    Tuesday, June 28, 2011 9:54 PM
  • I'm building a 32 bit app. I guess the total ram size, total memory free, and the total memory i can allocate would be required. Just out of curiosity, can u tell me what functions give me all those information about ram? And stupid me! I hadn't considered paging at all! :( I'll need to think about that. I guess if I use a little less memory than  what's freely available, it won't be paged?
    Wednesday, June 29, 2011 6:27 AM
  • I'm building a 32 bit app. I guess the total ram size, total memory free, and the total memory i can allocate would be required. Just out of curiosity, can u tell me what functions give me all those information about ram? And stupid me! I hadn't considered paging at all! :( I'll need to think about that. I guess if I use a little less memory than  what's freely available, it won't be paged?

    You can use GetPerformanceInfo, GetProcessMemoryInfo, and GlobalMemoryStatusEx functions for get system and application related memory information. you can find more information in the following                      

    http://msdn.microsoft.com/en-us/library/aa965225%28VS.85%29.aspx

     

    The following article "Memory Limits for Windows Releases" also useful.

    http://msdn.microsoft.com/en-us/library/aa366778%28VS.85%29.aspx


    Thanks and Regards Selvam http://www15.brinkster.com/selvamselvam/
    Wednesday, June 29, 2011 6:45 AM
  • I hadn't considered paging at all! :( I'll need to think about that. I guess if I use a little less memory than  what's freely available, it won't be paged?

    I don't think that is a safe bet.  Unfortunately we don't have much control over what is paged and what isn't.  And even if the RAM were free now you have very little control that some other process (or even Windows kernel/driver) won't want some of that physical RAM later.

    If you have a couple of hours to spend learning the basics, I highly recommend Mark Russinovich's "Mysteries of Windows Memory Management"  (both parts). It will at least let you know what the right questions to ask are.  Selvam has some good suggestions as to the APIs you might use, but as it sounds like your app may actually care about some of the subtleties that most of us can ignore, I would recommend the videos so you can understand the differences between all the types of memory.

    • Marked as answer by Rob Pan Monday, July 4, 2011 2:24 AM
    Wednesday, June 29, 2011 1:47 PM