Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread local storage memory usage

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

like image 843
ender Avatar asked Jun 16 '11 04:06

ender


1 Answers

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;
like image 120
CharithJ Avatar answered Sep 23 '22 02:09

CharithJ