线程本地存储内存使用

时间:2011-06-16 04:45:38

标签: c# thread-local-storage

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

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

澄清:

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

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

1 个答案:

答案 0 :(得分:2)

您可以按流程获取内存使用情况,如下所示。您可以使用其他几种内存测量here。但是,我不太确定是否有办法通过线程获取内存使用量。进程有Threads property,其中包含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;
相关问题