473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

available memory

Hi,
I wonder if it is possible to get hold of avaiable memory (only RAM) on a
machine through .Net class library? I do not want to call windws API.
I would like to use this to decide how many alive threads my program could
have each time the program runs. I use a number of threads in a simulation
tool.

Many thanks in advance.

Best regards
Kovan Akrei

Nov 16 '05 #1
5 8979
Hi Kovan,

You could use the PerformanceCounter class from System.Diagnostics.

Cheers,
Allan.
"Kovan Akrei" <ko****@ifi.uio.no> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,
I wonder if it is possible to get hold of avaiable memory (only RAM) on a
machine through .Net class library? I do not want to call windws API.
I would like to use this to decide how many alive threads my program could
have each time the program runs. I use a number of threads in a simulation
tool.

Many thanks in advance.

Best regards
Kovan Akrei

Nov 16 '05 #2
Check out the System.Management namespace. You can get things like
FreePhysicalMemory, TotalVisibleMemorySize

Yves

// Example class
class Class1
{
[STAThread]
static void Main(string[] args)
{
ManagementClass memoryClass = new
ManagementClass("Win32_OperatingSystem");
ManagementObjectCollection memory = memoryClass.GetInstances();
foreach (ManagementObject mo in memory)
{
foreach (PropertyData pd in mo.Properties)
{
Console.WriteLine("{0} : {1}", pd.Name, pd.Value);
}
}
Console.ReadLine();
}
}

// END OF EXAMPLE CLASS

"Kovan Akrei" <ko****@ifi.uio.no> schreef in bericht
news:%2****************@tk2msftngp13.phx.gbl...
Hi,
I wonder if it is possible to get hold of avaiable memory (only RAM) on a
machine through .Net class library? I do not want to call windws API.
I would like to use this to decide how many alive threads my program could
have each time the program runs. I use a number of threads in a simulation
tool.

Many thanks in advance.

Best regards
Kovan Akrei

Nov 16 '05 #3
Hi,
Thanks for replying. I have looked at that class, but I cant figure out how
this class is able to read available memory. There seems to be no
persformanceCounterType suitable for my use.
I have declared the following counter, with some shortages pointed out in
comments

PerformanceCounter PC = new PerformanceCounter("Memory", "GetMemory");

if(!PerformanceCounterCategory.Exists("Orders")) {
CounterCreationData mem = new CounterCreationData();
mem.CounterName = "mem";
mem.CounterType = PerformanceCounterType.?; // What kind of
PerformanceCounterType should I use

CounterCreationData memAvailable = new CounterCreationData();
memAvailable.CounterName = "Availabe memory";
memAvailable.CounterType = PerformanceCounterType.?; // What kind of
CounterType should I use

CounterCreationDataCollection ccds = new
CounterCreationDataCollection();
ccds.Add(memAvailable);
ccds.Add(mem);

PerformanceCounterCategory.Create("Memory","Retrei ves available
memory",ccds);
}
else
{
Console.WriteLine("Category exists - Memory");
}

What should I do after this? to gather and retrive memory info? I assume
that I could use PC.NextValue to retrieve next availabe samle in this
performance counter. Is my assumption right?

regards
Kovan

"Allan Taunt" <al*************@NO-hotmail-SPAM.com> wrote in message
news:e0**************@TK2MSFTNGP09.phx.gbl...
Hi Kovan,

You could use the PerformanceCounter class from System.Diagnostics.

Cheers,
Allan.
"Kovan Akrei" <ko****@ifi.uio.no> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,
I wonder if it is possible to get hold of avaiable memory (only RAM) on a machine through .Net class library? I do not want to call windws API.
I would like to use this to decide how many alive threads my program could have each time the program runs. I use a number of threads in a simulation tool.

Many thanks in advance.

Best regards
Kovan Akrei


Nov 16 '05 #4
Hi Kovan,

Simpler than that :-) You don't need to create a counter, use the built in
Memory, Available Bytes. ie:

PerformanceCounter pc = new PerformanceCounter("Memory","Available Bytes");
long availableMemory = Convert.ToInt64(pc.NextValue());
Console.WriteLine("Available Memory: {0}", availableMemory);

Cheers,
Allan.
"Kovan Akrei" <ko****@ifi.uio.no> wrote in message
news:uS**************@TK2MSFTNGP11.phx.gbl...
Hi,
Thanks for replying. I have looked at that class, but I cant figure out how this class is able to read available memory. There seems to be no
persformanceCounterType suitable for my use.
I have declared the following counter, with some shortages pointed out in
comments

PerformanceCounter PC = new PerformanceCounter("Memory", "GetMemory");

if(!PerformanceCounterCategory.Exists("Orders")) {
CounterCreationData mem = new CounterCreationData();
mem.CounterName = "mem";
mem.CounterType = PerformanceCounterType.?; // What kind of
PerformanceCounterType should I use

CounterCreationData memAvailable = new CounterCreationData();
memAvailable.CounterName = "Availabe memory";
memAvailable.CounterType = PerformanceCounterType.?; // What kind of
CounterType should I use

CounterCreationDataCollection ccds = new
CounterCreationDataCollection();
ccds.Add(memAvailable);
ccds.Add(mem);

PerformanceCounterCategory.Create("Memory","Retrei ves available
memory",ccds);
}
else
{
Console.WriteLine("Category exists - Memory");
}

What should I do after this? to gather and retrive memory info? I assume
that I could use PC.NextValue to retrieve next availabe samle in this
performance counter. Is my assumption right?

regards
Kovan

"Allan Taunt" <al*************@NO-hotmail-SPAM.com> wrote in message
news:e0**************@TK2MSFTNGP09.phx.gbl...
Hi Kovan,

You could use the PerformanceCounter class from System.Diagnostics.

Cheers,
Allan.
"Kovan Akrei" <ko****@ifi.uio.no> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,
I wonder if it is possible to get hold of avaiable memory (only RAM)
on
a machine through .Net class library? I do not want to call windws API.
I would like to use this to decide how many alive threads my program could have each time the program runs. I use a number of threads in a simulation tool.

Many thanks in advance.

Best regards
Kovan Akrei



Nov 16 '05 #5
Thanks Allan. That realy works :). By he way. Do you know how much memory
CLR allocates for a single thread (background and userthread) in a
multithreaded application? (I know that win32 OS allocates 1 MB of memory
for each process and are only able to support up to 2 GB om memory).

Kovan

"Allan Taunt" <al*************@NO-hotmail-SPAM.com> wrote in message
news:uD**************@TK2MSFTNGP11.phx.gbl...
Hi Kovan,

Simpler than that :-) You don't need to create a counter, use the built in Memory, Available Bytes. ie:

PerformanceCounter pc = new PerformanceCounter("Memory","Available Bytes"); long availableMemory = Convert.ToInt64(pc.NextValue());
Console.WriteLine("Available Memory: {0}", availableMemory);

Cheers,
Allan.
"Kovan Akrei" <ko****@ifi.uio.no> wrote in message
news:uS**************@TK2MSFTNGP11.phx.gbl...
Hi,
Thanks for replying. I have looked at that class, but I cant figure out

how
this class is able to read available memory. There seems to be no
persformanceCounterType suitable for my use.
I have declared the following counter, with some shortages pointed out in comments

PerformanceCounter PC = new PerformanceCounter("Memory", "GetMemory");

if(!PerformanceCounterCategory.Exists("Orders")) {
CounterCreationData mem = new CounterCreationData();
mem.CounterName = "mem";
mem.CounterType = PerformanceCounterType.?; // What kind of
PerformanceCounterType should I use

CounterCreationData memAvailable = new CounterCreationData();
memAvailable.CounterName = "Availabe memory";
memAvailable.CounterType = PerformanceCounterType.?; // What kind of
CounterType should I use

CounterCreationDataCollection ccds = new
CounterCreationDataCollection();
ccds.Add(memAvailable);
ccds.Add(mem);

PerformanceCounterCategory.Create("Memory","Retrei ves available
memory",ccds);
}
else
{
Console.WriteLine("Category exists - Memory");
}

What should I do after this? to gather and retrive memory info? I assume
that I could use PC.NextValue to retrieve next availabe samle in this
performance counter. Is my assumption right?

regards
Kovan

"Allan Taunt" <al*************@NO-hotmail-SPAM.com> wrote in message
news:e0**************@TK2MSFTNGP09.phx.gbl...
Hi Kovan,

You could use the PerformanceCounter class from System.Diagnostics.

Cheers,
Allan.
"Kovan Akrei" <ko****@ifi.uio.no> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> Hi,
> I wonder if it is possible to get hold of avaiable memory (only RAM)

on
a
> machine through .Net class library? I do not want to call windws API. > I would like to use this to decide how many alive threads my program

could
> have each time the program runs. I use a number of threads in a

simulation
> tool.
>
> Many thanks in advance.
>
> Best regards
> Kovan Akrei
>
>
>



Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Zac | last post by:
I've been googling all day and I haven't seen anyone else having this problem, so I thought I'd check to see if I'm unique or I should be expecting this behavior. I've recompiled and reinstalled...
5
by: Darren Dale | last post by:
I am doing linear algebra with large numarray. It is very efficient, but I have a small problem due to the size of my data. The dot product of a 10,000x3 double array with a 3x6,250,000 double...
7
by: Office Drone | last post by:
I'm a bit confused about memory usage, and for some reason I wasn't able to find a single point-of-call to get the amount of memory available. If we take, for instance, the Windows platform: ...
1
by: picard | last post by:
I have seen in various posts that there are tricks to increasing the largest continuous memory block available to an application on a windows machine. I want to prove this is possible using a...
5
by: Kovan Akrei | last post by:
Hi, I wonder if it is possible to get hold of avaiable memory (only RAM) on a machine through .Net class library? I do not want to call windws API. I would like to use this to decide how many...
1
by: sethwai | last post by:
Hi, We received an SQL 955 on a query. Since a snapshot showed that database wide memory was still available (high water mark was below max) I figured it was the SORTHEAP parm being too small. ...
4
by: comp.lang.php | last post by:
I wrote my own version of memory_get_usage() if that function is not available: if (!function_exists('memory_get_usage')) { /** * Determine the amount of memory you are allowed to have * *...
1
by: George2 | last post by:
Hello everyone, I am using Windows Server 2003. I am confused about the available (memory) value under Physical Memory category. From search there are two meanings, 1. available means free...
66
by: karthikbalaguru | last post by:
Hi, Will 'free' return the memory Immediately to the OS ? Thx in advans, Karthik Balaguru
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.