Try this one: Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS) Used like this: (vb 6 code) Dim MemStat As MEMORYSTATUS 'retrieve the memory status GlobalMemoryStatus MemStat MsgBox "You have" + Str$(MemStat.dwTotalPhys / 1024) + " Kb total memory and" + Str$(MemStat.dwAvailPageFile / 1024) + " Kb available PageFile memory."
The GlobalMemoryStatus function included in kernel32.dll yields very strange results. For example it claims that my 512MB RAM machine has just over 2.3 million terabytes of RAM (where one terabyte equals 1,099,511,627,776 bytes). Any suggestions?
Yes, patent that RAM compression technology, QUICK! :-) Actually, if you're sure your math is correct, no I don't have any suggestions. I didn't even see if it worked in .NET, I got some old code that worked in VB6 and assumed. You could write a new algorythm, I guess, if the return form GlobalMemoryStatus is consistant. You'd have to check it on a few machines with different amouts of RAM.
The algorythm idea seemed like a good one; I tweeked the numbers until the function produced an accurate result on my 512MB computer, but then took it over to a 256MB computer and the program spat out 431MB. Is the amount of RAM stored in the registry somewhere? Any other means of finding it?
The windows create memory in our computer, not only for the RAM, also for the free space in our discs( you know that). Could it be that toose values are some how related to this factor?? Just an ideia
I don't know if you have solved your problem, but I do have it too. I want simply get the available physical memory using c#.net. If you have any useful information, please respond. Thanks in advance.
using System.Runtime.InteropServices; ... public struct MemoryStatus { public uint Length; //Length of struct public uint MemoryLoad; //Value from 0-100 represents memory usage public uint TotalPhysical; public uint AvailablePhysical; public uint TotalPageFile; public uint AvailablePageFile; public uint TotalVirtual; public uint AvailableVirtual; } ... [DllImport("kernel32.dll")] public static extern void GlobalMemoryStatus(out MemoryStatus stat);
I think this has been answered already, but as per adam404 has indicated, you can do something like this (at least in c# 2005 beta) using System; using System.Collections.Generic; using System.Text; using Microsoft.VisualBasic.Devices; namespace PhysicalMemory { class Program { static void Main(string[] args) { ComputerInfo myCompInfo = new ComputerInfo(); Console.WriteLine("Physical Memory {0}", myCompInfo.TotalPhysicalMemory ); } } } (Note that you have to add a reference to Microsoft.VisualBasic to the project) Boogie
1 answers
I think you might be forced to do a Win32API call.
answered 2 years ago by:
0
I don't mind using an API, but as to which one to use or which function I do not know.
answered 2 years ago by:
0
Try this one:
Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)
Used like this: (vb 6 code)
Dim MemStat As MEMORYSTATUS
'retrieve the memory status
GlobalMemoryStatus MemStat
MsgBox "You have" + Str$(MemStat.dwTotalPhys / 1024) + " Kb total memory and" + Str$(MemStat.dwAvailPageFile / 1024) + " Kb available PageFile memory."
answered 2 years ago by:
0
What the hell does "Dim" and "Sub" mean??
only kidding ;)
answered 2 years ago by:
0
The GlobalMemoryStatus function included in kernel32.dll yields very strange results. For example it claims that my 512MB RAM machine has just over 2.3 million terabytes of RAM (where one terabyte equals 1,099,511,627,776 bytes). Any suggestions?
answered 2 years ago by:
0
Yes, patent that RAM compression technology, QUICK! :-)
Actually, if you're sure your math is correct, no I don't have any suggestions. I didn't even see if it worked in .NET, I got some old code that worked in VB6 and assumed.
You could write a new algorythm, I guess, if the return form GlobalMemoryStatus is consistant. You'd have to check it on a few machines with different amouts of RAM.
answered 2 years ago by:
0
The algorythm idea seemed like a good one; I tweeked the numbers until the function produced an accurate result on my 512MB computer, but then took it over to a 256MB computer and the program spat out 431MB. Is the amount of RAM stored in the registry somewhere? Any other means of finding it?
answered 2 years ago by:
0
The windows create memory in our computer, not only for the RAM, also for the free space in our discs( you know that). Could it be that toose values are some how related to this factor??
Just an ideia
answered 2 years ago by:
0
GlobalMemoryStatus only returns the Total memory in the system: Physical + Virtual
answered 2 years ago by:
0
So how can I find the physical RAM alone on the system? (Sorry this question is dragging on so long; I appreciate your patience.)
answered 2 years ago by:
0
I don't know if you have solved your problem, but I do have it too.
I want simply get the available physical memory using c#.net.
If you have any useful information, please respond.
Thanks in advance.
answered 2 years ago by:
0
using System.Runtime.InteropServices;
...
public struct MemoryStatus {
public uint Length; //Length of struct
public uint MemoryLoad; //Value from 0-100 represents memory usage
public uint TotalPhysical;
public uint AvailablePhysical;
public uint TotalPageFile;
public uint AvailablePageFile;
public uint TotalVirtual;
public uint AvailableVirtual;
}
...
[DllImport("kernel32.dll")]
public static extern void GlobalMemoryStatus(out MemoryStatus stat);
answered 2 years ago by:
0
You could use a WMI query, the property you need is TotalPhysicalMemory which is in the Win32_ComputerSystem class.
answered 2 years ago by:
0
I think this has been answered already, but as per adam404 has indicated, you can do something like this (at least in c# 2005 beta)
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualBasic.Devices;
namespace PhysicalMemory
{
class Program
{
static void Main(string[] args)
{
ComputerInfo myCompInfo = new ComputerInfo();
Console.WriteLine("Physical Memory {0}", myCompInfo.TotalPhysicalMemory );
}
}
}
(Note that you have to add a reference to Microsoft.VisualBasic to the project)
Boogie
answered 2 years ago by:
0
This post was imported from csharpfriends, if you have a similiar question please ask it again.
All previous members have been migrated, hope you enjoy the new platform!