开发者

Thread local storage memory usage

开发者 https://www.devze.com 2023-03-13 13:30 出处:网络
Is there a way in .NET to determine the amount of memory being taken up by thread-local storage? Specifically, I\'m looking开发者_如何学JAVA to find the amount of memory used by ThreadStatic objects

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

Specifically, I'm looking开发者_如何学JAVA 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


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消