下面是编程之家 jb51.cc 通过网络收集整理的代码片段。
编程之家小编现在分享给大家,也给大家做个参考。
用下面的方法,可以检查.NET给程序分配的内存数量
long available = GC.GetTotalMemory(false); Console.WriteLine(“Before allocations: {0:N0}”,available); int allocSize = 40000000; byte[] bigArray = new byte[allocSize]; available = GC.GetTotalMemory(false); Console.WriteLine(“After allocations: {0:N0}”,available);
Before allocations: 651,064 After allocations: 40,690,080
Process proc = Process.GetCurrentProcess(); Console.WriteLine(“Process Info: “+Environment.NewLine+ “Private Memory Size: {0:N0}”+Environment.NewLine + “Virtual Memory Size: {1:N0}” + Environment.NewLine + “Working Set Size: {2:N0}” + Environment.NewLine + “Paged Memory Size: {3:N0}” + Environment.NewLine + “Paged System Memory Size: {4:N0}” + Environment.NewLine + “Non-paged System Memory Size: {5:N0}” + Environment.NewLine,proc.PrivateMemorySize64,proc.VirtualMemorySize64,proc.WorkingSet64,proc.PagedMemorySize64,proc.PagedSystemMemorySize64,proc.NonpagedSystemMemorySize64 );
以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。