Computing.Net > Forums > Programming > Obtaining Memory Available

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Obtaining Memory Available

Reply to Message Icon

Name: dos4google
Date: April 25, 2008 at 09:50:07 Pacific
OS: Win
CPU/Ram: 1gb
Product: Dell
Comment:

Hi all I want to write a simple script to get the memory available on a machine using the mem command...Problem is mem returns a few lines of info, what is the best way to parse this and get the number that I want after typing the mem command?

Any help appreciated,



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: April 25, 2008 at 11:09:08 Pacific
Reply:

Just a request for clarification: you've got Windows, with 1 GB memory. MEM is a legacy 16-bit command that runs under the Virtual DOS machine (NTVDM.) It only ever reports a maximum of 640 KB of conventional memory and 1 MB (not 1 GB) of extended memory. Is this really the value you want to obtain, or are you looking for the amount of free memory available to Windows?


0

Response Number 2
Name: IVO
Date: April 25, 2008 at 12:52:46 Pacific
Reply:

More precisely mem reports up to 16 MB of extended and expanded memory, not just 1 MB. So stated, klint is right in pointing out mem is a legacy command bound to 16 bit memory addressing segmented architecture.


0

Response Number 3
Name: dos4google
Date: April 25, 2008 at 15:43:47 Pacific
Reply:

Hi thanks for the response - I really need to find out how
much memory is available on the machine to run an
application..Eg a script runs that works out that the machine
has a total of 1gb RAM available and then accordingly sets a
variable for the application to know to use half of the
memory available on the machine e.g 512mb....

I hope this makes things clearer, any advice would be
appreciated


0

Response Number 4
Name: Razor2.3
Date: April 28, 2008 at 02:16:30 Pacific
Reply:

"available" as in free, or "available" as in total?

And "RAM" as in physical memory or "RAM" as in physical memory + page file?

EDIT: Also, how do you want this number? B? KB? MB?


0

Response Number 5
Name: dos4google
Date: April 28, 2008 at 06:39:09 Pacific
Reply:

Hi,

I am after the RAM that is available in total. RAM in terms of Physical Memory,

So my machine has 3GB of RAM when I look at the System properties,

I would like to see the information in MB ideally

Thanks,


0

Related Posts

See More



Response Number 6
Name: Razor2.3
Date: April 28, 2008 at 18:40:00 Pacific
Reply:

So this is the type of problem VBScript with WMI excels at.

But it's not perfect: WMI needs to be running. This isn't normally a problem, but you never know how people modify their startup services. Also, this counts the total MB of each RAM module and adds them up, so it doesn't account for onboard devices stealing system memory. For instance, this PC has two 256MB chips in it, so the script reports 512MB; System Properties reports 504MB of RAM. Apparently, 8MB is reserved for the onboard video.

With that out of the way, this is a 6 line VBScript. If you're running it through cscript, it'll print the total MB of RAM. If not, it won't. Either way, the script will set the ERRORLEVEL to whatever it found. This allows you to do something like this from a command script:

totMem.vbs
SET /A halfMem=%ERRORLEVEL% / 2
yourApp -mem %halfMem%

Why? Because I'm really just that nice and it was one extra line.

Script follows:

For Each o In GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory")
mem = mem + CDbl(o.Capacity) / 2 ^ 20
Next
On Error Resume Next
WScript.StdOut.WriteLine mem
WScript.Quit mem


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Obtaining Memory Available

PHP error www.computing.net/answers/programming/php-error/11806.html

int 2f 08 get XMS www.computing.net/answers/programming/int-2f-08-get-xms-/12248.html

Small C program to exclude bad RAM www.computing.net/answers/programming/small-c-program-to-exclude-bad-ram-/11790.html