memory detect

This is a discussion on memory detect within the C Programming forums, part of the General Programming Boards category; How could I find out how much installed RAM a computer has? I would like to use C if possible, ...

  1. #1
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463

    memory detect

    How could I find out how much installed RAM a computer has? I would like to use C if possible, to make it portable, but I'd be happy with a Windows answer too(but I know this isn't the windows board )

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    I believe you have to query the BIOS in order to be portable...

    This site might be helpful:
    http://database.sarang.net/study/OS/...termine_memory
    Last edited by itsme86; 09-26-2004 at 12:10 PM.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    on linux you can just open up /proc/meminfo and find all kinds of information regarding memory (including total amount)

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    Quote Originally Posted by Perspective
    on linux you can just open up /proc/meminfo and find all kinds of information regarding memory (including total amount)
    It misreports the memory installed in my machine (1GB)
    Code:
    MemTotal:       905836 kB
    If you understand what you're doing, you're not learning anything.

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    ...interesting. i get this.. (1GB)

    MemTotal: 1035424 kB

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    Well, to be fair I do get this during bootup which I've never bothered fixing:
    Code:
    Linux version 2.6.7 (root@itsme) (gcc version 3.3.4) #1 Mon Jul 5 05:24:34 PDT 2004
    BIOS-provided physical RAM map:
     BIOS-e820: 0000000000000000 - 000000000009fc00 (usable)
     BIOS-e820: 000000000009fc00 - 00000000000a0000 (reserved)
     BIOS-e820: 00000000000f0000 - 0000000000100000 (reserved)
     BIOS-e820: 0000000000100000 - 000000003fff0000 (usable)
     BIOS-e820: 000000003fff0000 - 000000003fff3000 (ACPI NVS)
     BIOS-e820: 000000003fff3000 - 0000000040000000 (ACPI data)
     BIOS-e820: 00000000fec00000 - 00000000fec01000 (reserved)
     BIOS-e820: 00000000fee00000 - 00000000fee01000 (reserved)
     BIOS-e820: 00000000ffff0000 - 0000000100000000 (reserved)
    Warning only 896MB will be used.
    Use a HIGHMEM enabled kernel.
    896MB LOWMEM available.
    If you understand what you're doing, you're not learning anything.

  7. #7
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    thanks for the website, I'll look through and try it

  8. #8
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Quote Originally Posted by itsme86
    Well, to be fair I do get this during bootup which I've never bothered fixing:

    Then why are you complaining about /proc/meminfo misreporting the amount of ram you have?
    hello, internet!

  9. #9
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    For Windows, check out GlobalMemoryStatus on the MSDN
    (< http://msdn.microsoft.com/library/en...morystatus.asp >)

  10. #10
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    Quote Originally Posted by moi
    Then why are you complaining about /proc/meminfo misreporting the amount of ram you have?
    I wasn't "complaining". I was making a point. And that point was that it doesn't always necessarily tell you how much RAM is installed if your OS is broken, whereas my BIOS query theory should work regardless.
    If you understand what you're doing, you're not learning anything.

  11. #11
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    I believe you have to query the BIOS in order to be portable
    Is there a portable way to query the BIOS?

  12. #12
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Quote Originally Posted by itsme86
    I wasn't "complaining". I was making a point. And that point was that it doesn't always necessarily tell you how much RAM is installed if your OS is broken, whereas my BIOS query theory should work regardless.
    And what's the point of knowing about ram that may or may not be there if your OS can't use it?

    Quote Originally Posted by bithub
    Is there a portable way to query the BIOS?
    No
    hello, internet!

  13. #13
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    Quote Originally Posted by moi
    And what's the point of knowing about ram that may or may not be there if your OS can't use it?



    No
    You need an exampe? Hardware inventory checking.
    If you understand what you're doing, you're not learning anything.

  14. #14
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    The theory of querying bios is portable. The code to do so isn't necessarily portable unless you are sticking with a GCC compiler. So code writen for a linux machine can be compiled via mingw and work all find and dandy, however that same code won't compile under VC++ which only handles masm style assembler syntax.

  15. #15
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,544
    > The theory of querying bios is portable.
    Until you come across machines which don't have an IBM-PC compatible BIOS - say a Sun workstation for example.
    How do you work out the answer to this question for your GB environment?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 11-19-2007, 09:28 AM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Suggestions on this C style code
    By Joelito in forum C Programming
    Replies: 11
    Last Post: 06-07-2007, 03:22 AM
  4. Relate memory allocation in struct->variable
    By Niara in forum C Programming
    Replies: 4
    Last Post: 03-23-2007, 03:06 PM
  5. Memory allocation and deallocation
    By Micko in forum C++ Programming
    Replies: 3
    Last Post: 08-19-2005, 06:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21