线程本地存储内存使用情况

发布于 2024-11-15 13:45:30 字数 449 浏览 6 评论 0原文

.NET 中有没有办法确定线程本地存储占用的内存量?

具体来说,我希望找到 ThreadStatic 对象使用的内存量以及分配给线程数据槽中对象的内存量(例如通过调用 Thread.SetData)。

澄清一下:

线程本地存储: http://msdn.microsoft.com/en-us/library/6sby1byh.aspx

线程本地存储:线程相关静态字段和数据槽 http://msdn.microsoft.com/en-us/library/6sby1byh.aspx

Is there a way in .NET to determine the amount of memory being taken up by thread-local storage?

Specifically, I'm looking to find the amount of memory used by ThreadStatic objects and by memory allocated to objects in the Thread data slots (e.g. by calling Thread.SetData).

To clarify:

Thread-local storage:
http://msdn.microsoft.com/en-us/library/6sby1byh.aspx

Thread Local Storage: Thread-Relative Static Fields and Data Slots
http://msdn.microsoft.com/en-us/library/6sby1byh.aspx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是一片海 2024-11-22 13:45:30

您可以按如下方式获取进程的内存使用情况。您还可以在此处使用其他几种内存测量值。但是,我不太确定是否有办法通过线程获取内存使用情况。进程有 Threads 属性,它由一个集合组成ProcessThread 正是您感兴趣的,但不是获取内存使用情况的直接方法。

// Get the current process.
Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();

// Gets the amount of physical memory allocated for the associated process.
long totalNumberOfBytesUsed = currentProcess.WorkingSet64;

You can get the memory usage by process as below. There are several other memory measurements that you can use here. But, I am not quite sure whether there is a way to get the memory usage by thread. Process has Threads property which consists of a collection of ProcessThreads which is exactly what you are interested in, but not straight forward way to get the memory usage.

// Get the current process.
Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();

// Gets the amount of physical memory allocated for the associated process.
long totalNumberOfBytesUsed = currentProcess.WorkingSet64;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文