有没有一种方法来检索一个C#应用程序的当前内存使用情况? [英] Is there a way to retrieve a C# app's current memory usage?
问题描述
我自动化一些分析任务,并要记录的堆空间,并生成大小实时性。该分析API 看起来太过复杂,我需要的东西,它似乎对个人的分配监听和收藏,这是不是对我来说很重要。性能分析工具当然是一个很大的帮助,但我一直在寻找一个更灵活,可编程接口。
I am automating some profiling tasks and want to log heap space and generation sizes real-time. The profiling API seems awfully complicated for what I need, and it seems to listen in on individual allocations and collections, which isn't that important to me. Profiling tools are a great help of course, but I was looking for a more flexible, programmable interface.
推荐答案
术语当前内存使用'是有点松散定义。你的意思是工作集?不管这意味着,你可以使用不同的属性,如 VirtualMemorySize
,工作集
, PrivateMemorySize
等,从工艺类来检索它。
The term 'current memory usage' is a little loosely defined. Do you mean the working set? Whatever it means, you can use different properties such as VirtualMemorySize
, WorkingSet
, PrivateMemorySize
, etc. from the process class to retrieve it.
long workingSet = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
这篇关于有没有一种方法来检索一个C#应用程序的当前内存使用情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!