复制代码 代码如下:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
///
/// 包含各种内存管理、优化的方法
///
public class Memory
{
private static readonly Version myVersion = new Version(1, 0);
///
/// 将当前进程的内存占用尺寸设置到最小
///
///
public static int SetProcessMemoryToMin()
{
return SetProcessMemoryToMin(Process.GetCurrentProcess().Handle);
}
///
/// 将内存占用尺寸设置到最小
///
/// 需要设置内存使用范围的程序进程句柄,一般为当前进程, 如:System.Diagnostics.Process.GetCurrentProcess().Handle
///
public static int SetProcessMemoryToMin(IntPtr SetProcess)
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
return SetProcessWorkingSetSize(SetProcess, -1, -1);
}
return -1;
}
[Dllimport("kernel32.dll")]
private static extern int SetProcessWorkingSetSize(IntPtr hProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);
}



