我需要检查多少内存在堆中分配的。有没有办法让这个值编程使用C#?
I need to check how much memory is allocated in the heap. Is there a way to get this value programmatically with C#?
我知道关于 System.Runtime.InteropServices.Marshal.SizeOf(...)
,但只告诉我一个物体的大小。
I know about the System.Runtime.InteropServices.Marshal.SizeOf(...)
but that only tells me the size of an object.
使用PerformanceCounter您可以查询字节数在所有堆,从自己的过程,甚至是其他进程。
Using a PerformanceCounter you can query the "# Bytes in all Heaps", from your own process, and even other processes.
使用的范畴.NET CLR内存看到很多可用的计数器。
Use the Category ".Net CLR Memory" to see a lot of counters available.
您必须看到在系统负载的不同之处是提出了乔恩飞碟双向的的PerformanceCounter和GC.GetTotalMemory之间有什么。
You have to see what the difference in system load is between the PerformanceCounter and the GC.GetTotalMemory that is proposed by Jon Skeet.