如何获得当前程序使用的物理内存的大小!请高手指点!
解决方案 »
- C#与C++的类型问题
- wcf binding问题。。高手们进!!
- 项目反编译
- C#实现WEB服务
- C# winform 如何删除flash的SharedObjects
- Windows2003下如何设置IIS才可以使用WebClient上传?
- 在vs.net下写了一句Console.WriteLine("hello");运行后,怎样才能看结果.谢谢
- CSDN主页的XML,谁有最简单的程序可以下载文章的,并且能随时更新
- IIS 寄宿 wcf 问题。数据清空了。
- C#可以将文件名中的拼音翻译成"中文"吗?
- 在VS2005中手写事件与应用系统自己的事件有什么不同?
- 还是关于webform用户控件:自定义的属性在设计器里,有时可以浏览,有时不能...
[DllImport("kernel32")]
public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);
//定义内存的信息结构
[StructLayout(LayoutKind.Sequential)]
public struct MEMORY_INFO
{
public uint dwLength;
public uint dwMemoryLoad;
public uint dwTotalPhys;
public uint dwAvailPhys;
public uint dwTotalPageFile;
public uint dwAvailPageFile;
public uint dwTotalVirtual;
public uint dwAvailVirtual;
}
//调用GlobalMemoryStatus函数获取内存的相关信息
MEMORY_INFO MemInfo;
MemInfo = new MEMORY_INFO();
GlobalMemoryStatus(ref MemInfo);
MemoryLoad.Text = MemInfo.dwMemoryLoad.ToString()+"%的内存正在使用";
TotalPhys.Text = "物理内存共有"+MemInfo.dwTotalPhys.ToString()+"字节";
AvailPhys.Text = "可使用的物理内存有"+MemInfo.dwAvailPhys.ToString()+"字节";
TotalPageFile.Text = "交换文件总大小为"+MemInfo.dwTotalPageFile.ToString()+"字节";
AvailPageFile.Text = "尚可交换文件大小为"+MemInfo.dwAvailPageFile.ToString()+"字节";
TotalVirtual.Text = "总虚拟内存有"+MemInfo.dwTotalVirtual.ToString()+"字节";
AvailVirtual.Text = "未用虚拟内存有"+MemInfo
http://topic.csdn.net/t/20060220/15/4566076.html
#include <stdio.h>
#include "psapi.h"void PrintMemoryInfo( DWORD processID )
{
HANDLE hProcess;
PROCESS_MEMORY_COUNTERS pmc; // Print the process identifier. printf( "\nProcess ID: %u\n", processID ); // Print information about the memory usage of the process. hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
if (NULL == hProcess)
return; if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) )
{
printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount );
printf( "\tPeakWorkingSetSize: 0x%08X\n",
pmc.PeakWorkingSetSize );
printf( "\tWorkingSetSize: 0x%08X\n", pmc.WorkingSetSize );
printf( "\tQuotaPeakPagedPoolUsage: 0x%08X\n",
pmc.QuotaPeakPagedPoolUsage );
printf( "\tQuotaPagedPoolUsage: 0x%08X\n",
pmc.QuotaPagedPoolUsage );
printf( "\tQuotaPeakNonPagedPoolUsage: 0x%08X\n",
pmc.QuotaPeakNonPagedPoolUsage );
printf( "\tQuotaNonPagedPoolUsage: 0x%08X\n",
pmc.QuotaNonPagedPoolUsage );
printf( "\tPagefileUsage: 0x%08X\n", pmc.PagefileUsage );
printf( "\tPeakPagefileUsage: 0x%08X\n",
pmc.PeakPagefileUsage );
} CloseHandle( hProcess );
}void main( )
{
// Get the list of process identifiers. DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i; if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return; // Calculate how many process identifiers were returned. cProcesses = cbNeeded / sizeof(DWORD); // Print the memory usage for each process for ( i = 0; i < cProcesses; i++ )
PrintMemoryInfo( aProcesses[i] );
}
{
[DllImport("psapi.dll")]
public static extern int GetProcessMemoryInfo( System.IntPtr hProcess, ref PROCESS_MEMORY_COUNTERS ppsmemCounters, int cb );
[StructLayout(LayoutKind.Sequential)]
public struct PROCESS_MEMORY_COUNTERS
{
public int cb;
public int PageFaultCount;
public uint PeakWorkingSetSize;
public uint WorkingSetSize;
public uint QuotaPeakPagedPoolUsage;
public uint QuotaPagedPoolUsage;
public uint QuotaPeakNonPagedPoolUsage;
public uint QuotaNonPagedPoolUsage;
public uint PagefileUsage;
public uint PeakPagefileUsage;
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
PROCESS_MEMORY_COUNTERS pmc = new PROCESS_MEMORY_COUNTERS(); int bs = Class1.GetProcessMemoryInfo( p.Handle , ref pmc , Marshal.SizeOf( pmc.GetType() ));
}
NonpagedSystemMemorySize 获取分配给此进程的未分页的系统内存大小。
PagedMemorySize 获取分页的内存大小。
PagedSystemMemorySize 获取分页的系统内存大小。
PeakPagedMemorySize 获取峰值分页内存大小。
PeakVirtualMemorySize 获取峰值虚拟内存大小。
PrivateMemorySize
proc.NonpagedSystemMemorySize()即为当前进程的物理内存大小