有没有办法检索 C# 应用程序的当前内存使用情况? [英] Is there a way to retrieve a C# app's current memory usage?

查看:27
本文介绍了有没有办法检索 C# 应用程序的当前内存使用情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自动执行一些分析任务,并希望实时记录堆空间和代大小.profiling 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.

推荐答案

术语当前内存使用情况"的定义有点松散.你是说工作集吗?无论它意味着什么,您都可以使用流程类中的不同属性(例如 VirtualMemorySizeWorkingSetPrivateMemorySize 等)来检索它.>

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆